Find Minimum Time to Finish All Jobs
Real-world version: Handing Out Runs to Keep the Longest Shift ShortThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def minimum_time_required(runs: list[int], k: int) -> int:public int minimumTimeRequired(int[] runs, int k)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Beautiful ArrangementReal-world version: Divisible Crate PlacementsMedium
- Partition to K Equal Sum SubsetsReal-world version: Dealing Counterweights Onto HoistsMedium
- Shopping OffersReal-world version: Cheapest Basket at the Fastener CounterMedium
- Matchsticks to SquareReal-world version: Fencing a Square From Every RodMedium