BackmediumUncategorized uncategorized medium

Optimal Cargo Allocation Solution

Problem Statement

Given a list of crate weights and the maximum capacity of carts, determine the maximum number of crates that can be allocated to each cart such that the total weight does not exceed the cart capacity.

Example 1
Input
crateWeights = [12, 17, 20, 22], cartCapacity = 17
Output
0

Explanation: We can allocate 2 crates with weights 12 and 5 to each cart.

Constraints

  • The crate weights are positive integers.
  • The cart capacity is a positive integer.
  • The maximum number of crates that can be allocated to each cart is a positive integer.
  • The total weight of crates allocated to each cart does not exceed the cart capacity.
  • The total number of crates allocated to all carts is equal to the total number of crates.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free