Signing booth pairing
MediumOnline Assessment
Staff every session of a conference with a sign-language interpreter so that the interpreters spend as little time preparing as possible.
There are n sessions and n interpreters, and every session needs exactly one interpreter, who covers only that session. prep[i][j] is the number of minutes interpreter j must prepare to cover session i (technical vocabulary, speaker slides, and so on), or -1 if interpreter j cannot cover session i at all (not certified in that language, or double-booked). Note that 0 is a valid preparation time.
Choose an interpreter for every session, using each interpreter once and never an unavailable pairing, so that the total preparation time is as small as possible. Many assignments can tie for the minimum; among those, return the one that is lexicographically smallest as a list: compare the interpreter for session 0 first, then for session 1, and so on.
Input: prep, an n x n list of lists of integers.
Output: a list a of length n where a[i] is the 0-based index of the interpreter covering session i. Return [] if no complete assignment exists (and also when n is 0).
Example 1
- Input:
- [[[-1,2,2,1],[0,2,1,0],[-1,2,2,1],[1,2,2,-1]]]
- Output:
- [1,0,3,2]
- Explanation
- Interpreter 0 cannot cover sessions 0 or 2, and interpreter 3 cannot cover session 3. Five minutes is the best total, reached by several assignments, such as
[1, 0, 3, 2](2 + 0 + 1 + 2),[1, 2, 3, 0]and[3, 0, 1, 2]. The lexicographically smallest of them is[1, 0, 3, 2], because no optimal assignment starts with0.
Example 2
- Input:
- [[[1,2,8],[1,9,7],[3,4,5]]]
- Output:
- [1,0,2]
- Explanation
- Handing each session its cheapest free interpreter in turn gives
[0, 2, 1]for 1 + 7 + 4 = 12 minutes. The best total is 8, from[1, 0, 2](2 + 1 + 5): session 0 gives up its cheapest interpreter so session 1 can use it.
Example 3
- Input:
- [[[-1,3],[-1,4]]]
- Output:
- []
- Explanation
- Sessions 0 and 1 both need interpreter 0 but cannot use it, so no complete assignment exists and the answer is
[].
Constraints
0 <= n <= 12wheren = prep.lengthand every row ofprephas lengthn- each
prep[i][j]is-1or an integer from0to1,000