All problems
0725MediumArrayBinary SearchGreedy

Evening Out The Van Loads

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2064Minimized Maximum of Products Distributed to Any Store

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A sorting hub has couriers vans on the yard tonight and a depot list loads, where loads[i] is the number of parcels waiting at depot i.

Every parcel has to be moved. A van is sent to at most one depot, so everything it carries comes from that single depot, and a van may also be left on the yard carrying nothing. The parcels of a depot may be split between the vans sent to it in any whole numbers you like.

Plan the run so that the heaviest van load is as small as it can be, and return that load.

Examples

Example 1

Input
couriers = 6, loads = [11, 6]
Output
3

Send four vans to the first depot carrying 3, 3, 3 and 2 parcels, and two vans to the second carrying 3 each. That is six vans, every parcel is moved, and no van carries more than 3.

Example 2

Input
couriers = 3, loads = [10, 1, 1]
Output
10

The two single-parcel depots each need a van of their own, which leaves one van for the depot holding 10, and that van has to take all 10.

Example 3

Input
couriers = 4, loads = [6, 2]
Output
2

Three vans take 2 parcels each from the first depot and the fourth van takes both parcels of the second depot, so the heaviest van carries 2.

Constraints

  • 1 <= loads.length <= couriers <= 10^5
  • 1 <= loads[i] <= 10^5

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def min_largest_van_load(couriers: int, loads: list[int]) -> int:
Java
public int minLargestVanLoad(int couriers, int[] loads)
September 7
Apply