Code RoomKitchen prep order
EasyPrep Room Coding #4772

Kitchen prep order

CodingAlgorithms & data structuresEntry–Mid~18 min

A kitchen prep board holds the jobs for one service. Job i is named tasks[i], and needs[i] holds the positions of the jobs that must be finished before job i may start, so an empty entry there means job i can start whenever. Job names are distinct, and a position listed twice inside one needs entry means nothing extra. One cook works the board alone and starts a job only once every job it needs is finished. When several jobs are ready at the same moment the cook takes the one whose name comes first alphabetically, not the one sitting earliest on the board. Return the job names in the order the cook finishes them. Return an empty list when the board can never be cleared, which covers a job that needs itself and any ring of jobs waiting on each other.

Implement
prep_task_order(tasks: list[str], needs: list[list[int]]) → list[str]
Examples
in[["dice onions","boil stock","toast bread"],[[],[0],[]]]out["dice onions","boil stock","toast bread"]
in[["glaze","proof","shape"],[[2],[],[1]]]out["proof","shape","glaze"]
in[["reduce sauce","skim sauce"],[[1],[0]]]out[]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 18 min
InputExpectedGot
[["dice onions","boil stock","toast bread"],[[],[0],[]]]["dice onions","boil stock","toast bread"]not run yetsample
[["glaze","proof","shape"],[[2],[],[1]]]["proof","shape","glaze"]not run yetsample
[["reduce sauce","skim sauce"],[[1],[0]]][]not run yetsample