Data labeling scheduler with prefix-balanced models
I was asked this
No reports yet. Sign in to say where you were asked it.
A data labeling platform pairs tasks, AI models and human annotators. IDs are 1-indexed strings: tasks "t1"…"t{totalTask}", models "m1"…"m{totalModel}", humans "h1"…"h{totalHuman}".
An assignment is a triple [task, model, human]: that human labels that task with help from that model. A task may appear in many assignments, with different humans and models.
Part 1: any valid schedule
Implement schedule(totalTask, totalModel, totalHuman, k) -> list[list[str]]. It returns a list of assignments such that:
- Every human appears in at least
kassignments. - No human is assigned the same task twice.
- Every ID is within its range.
Return any valid schedule. If no valid schedule exists, return [].
Constraints: 1 <= totalTask, totalModel, totalHuman <= 100, 0 <= k.
Example: totalTask = 4, totalModel = 1, totalHuman = 3, k = 2. One valid answer:
[["t1","m1","h1"], ["t2","m1","h2"], ["t3","m1","h3"],
["t2","m1","h1"], ["t3","m1","h2"], ["t4","m1","h3"]]
k = 5 with totalTask = 4 has no answer, so it returns [].
Part 2: prefix-balanced schedule
Now the order of the list matters. Look at every prefix, meaning the first x assignments for each x >= 1. In every prefix:
- Per task: for each task, the counts of each model it was used with differ by at most 1. Models used 0 times count as 0.
- Per human: for each human, the counts of each model they used differ by at most 1, counted the same way.
Implement balanced_schedule(totalTask, totalModel, totalHuman, k). It must meet all of the Part 1 rules plus this one, or return [] if that is impossible.
Example: totalTask = 3, totalModel = 2, totalHuman = 2, k = 2. One valid answer:
[["t1","m1","h1"], ["t1","m2","h2"], ["t2","m2","h1"], ["t2","m1","h2"]]
After the first assignment, t1 has m1:1, m2:0, which is fine. After all four, every task and every human has used each model once.
Part 3 (if time allows): streaming
Humans join one at a time. When a human joins, emit their assignments immediately, and never reorder what you already emitted. The whole stream must stay valid and prefix-balanced after every emission. State the time and the memory your scheduler keeps.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to submit your code; every attempt is kept here.
