Katkat

Implement ordering and undo executor

NetflixSoftware Engineer · Onsite

Last 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:

  1. 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.

  2. 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.