Minimize Maximum Parcels
Learn this problemProblem statement
You are give:
Our mission this time is to help the company calculate the minimum possible value of the maximum number of packages assigned to any delivery center after distributing all the extra packages optimally.
Function
minimizeMaximumParcels(packages: int[], extra_packages: long) → longExamples
Example 1
packages = [7, 5, 1, 9, 1]extra_packages = 25return = 10With packages = [7, 5, 1, 9, 1] and extra_packages = 25, the goal is to make the maximum as small as possible.
If we set a cap of 10, the additional packages needed to raise each center up to 10 are (10-7) + (10-5) + (10-1) + (10-9) + (10-1) = 3 + 5 + 9 + 1 + 9 = 27, which is at least the 25 extra packages available, so a maximum of 10 is achievable.
One optimal assignment uses exactly 25 extra packages: add 3, 5, 9, 1, and 8 to the centers respectively, giving totals [10, 10, 10, 10, 9]. The maximum is 10.
A cap of 9 would require (9-7) + (9-5) + (9-1) + (9-1) = 2 + 4 + 8 + 8 = 22 just to bring the four under-9 centers up to 9, but center 4 already holds 9 and cannot be lowered, and distributing all 25 extra packages forces at least one center above 9. Therefore 9 is not achievable, and the answer is 10.
Example 2
packages = [1, 2, 3]extra_packages = 3return = 3Example 3
packages = [1]extra_packages = 3return = 4Constraints
1 <= packages.length <= 1051 <= packages[i] <= 1091 <= extra_packages <= 1015- The return value may exceed 32-bit integer range and should be treated as a 64-bit integer.
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026