Hard data structure and algorithm practice puzzle.
Given the free units of a resource, what each process still needs, and what each already holds, return whether the state is safe. Safe means there is some order in which every process can finish: run anyone whose remaining need fits in what is free, take back everything they held when they are done, and repeat. If you ever get stuck with nobody able to run, the state can deadlock. Dijkstra's answer from 1965, and the reason greedy is correct here is that a process you can finish never becomes harder to finish later.
Solve it three ways: snap the jigsaw pieces together, fill in the blanks, or type it from scratch against the tests. This one is free.
Browse all 536 puzzles