Implement ordering and undo executor
NetflixSoftware Engineer · OnsiteLast updated
This question evaluates graph algorithm skills (topological ordering and cycle detection) and software design competencies related to command interfaces, undo semantics, and shared-state management.
The interview included two coding tasks:
-
Dependency ordering: Given a set of tasks and their dependency relationships, return a valid execution order so that every task appears after all of its prerequisites. If no valid order exists because of a cycle, report that the schedule is impossible.
-
Command executor with undo: Design and implement a simple command executor that supports:
execute(command): runs a command and records enough information to undo it later.undo(): reverts the most recently executed command that has not yet been undone.
Assume commands may modify shared application state. Discuss the interface you would use for commands, what data structure you would use to support undo, and how you would handle edge cases such as calling undo() when no command has been executed.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.