All problems
1143HardArrayDynamic ProgrammingBacktrackingBit ManipulationBitmask

Handing Out Runs to Keep the Longest Shift Short

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1723Find Minimum Time to Finish All Jobs

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 depot has runs to hand out, and runs[i] is how long run i takes. Every run goes to exactly one of k drivers, and a driver's shift is the total time of the runs handed to them. A driver may end up with no runs at all.

Hand out every run so that the longest shift is as short as it can be, and return that length.

Examples

Example 1

Input
runs = [3, 3, 2, 2, 2], k = 2
Output
6

Giving one driver the two runs of 3 and the other the three runs of 2 makes both shifts 6, and since the whole total is 12 no shorter longest shift is possible.

Example 2

Input
runs = [5, 5], k = 2
Output
5

One run each, so both shifts come to 5.

Example 3

Input
runs = [10, 1, 1], k = 2
Output
10

Some driver has to take the run of 10 whatever else happens, so the longest shift is at least that, and the other driver can take both short runs.

Constraints

  • 1 <= k <= runs.length <= 12
  • 1 <= runs[i] <= 10^7

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 minimum_time_required(runs: list[int], k: int) -> int:
Java
public int minimumTimeRequired(int[] runs, int k)
September 7
Apply