FastPrepFastPrep
Problem Brief

Distribute Packages

OA
See Amazon online assessment and hiring insights

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 Description

Complete the function distributePackages in the editor.

distributePackages has the following parameters:

  1. 1. int[] trucks: an array of integers representing the quantity of each truck
  2. 2. int to_distribute: the number of packages to distribute

Returns

int[]: an array representing the distributed packages across the trucks

1Example 1

Input
trucks = [2, 3, 4, 5, 6], to_distribute = 10
Output
[6, 6, 6, 6, 6]
Explanation
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

Limits and guarantees your solution can rely on.

๐Ÿ‡๐Ÿ‡
public int[] distributePackages(int[] trucks, int to_distribute) {
  // write your code here
}
Input

trucks

[2, 3, 4, 5, 6]

to_distribute

10

Output

[6, 6, 6, 6, 6]

Sign in to submit your solution.