Monday's operating rooms
- O(2ⁿ) · Legendary
- Full plan
- Python
- JavaScript
- recursion
- lists
- comparisons
Problem
First thing Monday morning there are as many operations as surgeons, and Dr. Steven Hart, head of surgery, has to hand them out: each surgeon gets exactly one operation and no operation is left without a surgeon. Each surgeon takes a different time for each operation, and the doctor wants the minutes of everyone, added up, to be as few as possible.
Write a function that takes times, a list of lists of whole numbers from 0 up: times[i][j] is how many minutes surgeon i takes for operation j. There are as many rows as columns, at most 7, and the list may be empty. Return a whole number: the lowest total of minutes that such an assignment can reach.
With [[3, 5, 4], [2, 6, 7], [5, 3, 9]]: if surgeon 0 does operation 2 (4 minutes), surgeon 1 operation 0 (2) and surgeon 2 operation 1 (3), that adds up to 9, and no other assignment goes lower. If each surgeon, in order, took the free operation that is fastest for them, surgeon 0 would get operation 0 (3) and the others would be left with 6 and 9:
18. With [[2, 3], [3, 9]] it pays to cross them: 3 + 3 = 6. With no surgeons, 0.
Examples
The example
[[3, 5, 4], [2, 6, 7], [5, 3, 9]] → 9
Crossed
[[2, 3], [3, 9]] → 6
Taking the fastest first does not work
[[1, 2, 9, 9], [2, 50, 9, 9], [9, 9, 1, 2], [9, 9, 2, 50]] → 8
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def least_time(times):
passJavaScript
function leastTime(times) {
}It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.