Problem · Array
Distribute Packages
Learn this problemProblem statement
Amazon has to distribute multiple packages across all of their delivery trucks. Given an array of trucks where trucks[i] represents the ith truck quantity. We also have another input to_distribute which states the number of packages we want to distribute across all the trucks. So how would we distribute the to_distribute number such that the max total of each truck is minimized?
Function
distributePackages(trucks: int[], to_distribute: int) → int[]
Complete the function distributePackages in the editor.
distributePackages has the following parameters:
- 1.
int[] trucks: an array of integers representing the quantity of each truck - 2.
int to_distribute: the number of packages to distribute
Returns
int[]: an array representing the distributed packages across the trucks
Examples
Example 1
trucks = [2, 3, 4, 5, 6]to_distribute = 10return = [6, 6, 6, 6, 6]This means that 4 packages go to the first truck, 3 packages to the second truck, 2 packages to the third truck, 1 package to the fourth truck, and none to the fifth truck, resulting in each truck having a total of 6 packages.
Constraints
🍇🍇More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026