AAmazon·DSASDE-1Online Assessment
Minimum Number of Trips to Deliver All Packages
Problem
You are given n packages with weights weights[i] and a truck with capacity C. Each trip the truck can carry any subset of packages as long as the total weight does not exceed C. Find the minimum number of trips to deliver all packages.
Example
weights = [1, 2, 3, 4], C = 5
Output: 2 -- trips: {1,4} and {2,3}
Constraints
- 1 ≤ n ≤ 20
- 1 ≤ weights[i] ≤ C ≤ 10^4
Follow-up
What if the truck must return to the depot between trips and each return costs 1 unit of fuel?
added 6 days ago