FastPrepUndo and Redo Command History
Problems/Undo and Redo Command History

Undo and Redo Command History

Netflix logoNetflix● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Netflix onsite interview for a full-time role. The report describes a command-history exercise with undo, and a follow-up with redo. It does not define the command data or how the answer is written. So here the input is a finite sequence of command identifiers. After every operation, you return the active history.

Maintain an active command history while processing a sequence of operations.

Each row in operations has one of these forms:

  • ["EXECUTE", command]: append the nonempty, case-sensitive command identifier to the active history. Executing a new command clears every command currently available for redo.
  • ["UNDO"]: remove the most recently active command and make it available for redo. If the active history is empty, do nothing.
  • ["REDO"]: restore the most recently undone command to the end of the active history. If no command is available for redo, do nothing.

After every operation, encode the complete active history as one string. Join its command identifiers in application order with |. Encode an empty active history as the empty string.

Return the encoded snapshots in operation order.

Function

runUndoRedoHistory(operations: String[][]) → String[]

Examples

Example 1

operations = [["EXECUTE","build"],["EXECUTE","test"],["UNDO"],["REDO"]]return = ["build","build|test","build","build|test"]

The undo removes test from the active history, and redo restores that same command.

Example 2

operations = [["EXECUTE","a"],["EXECUTE","b"],["EXECUTE","c"],["UNDO"],["UNDO"],["EXECUTE","d"],["REDO"],["UNDO"]]return = ["a","a|b","a|b|c","a|b","a","a|d","a|d","a"]

After two undos, executing d clears the redo branch. The following redo is therefore a no-op, and the final undo removes d.

Example 3

operations = [["UNDO"],["REDO"],["EXECUTE","x"],["UNDO"],["UNDO"],["REDO"],["REDO"]]return = ["","","x","","","x","x"]

Undo and redo are no-ops when their corresponding history is empty. The command x can be restored only once.

Constraints

  • 1 <= operations.length <= 500
  • Each row is exactly ["UNDO"], ["REDO"], or ["EXECUTE", command].
  • 1 <= command.length <= 100.
  • Each command identifier contains only uppercase or lowercase ASCII letters, digits, underscores, or hyphens and is compared by exact, case-sensitive equality.
  • The total number of command identifiers across all returned snapshots is at most 125000.

More Netflix interview questions

  • Timed Cache with Sidecar CleanupPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Score-Rotating Movie PlaylistONSITE INTERVIEW · Seen Sep 2026
  • Balanced Tree Node ReportONSITE INTERVIEW · Seen Aug 2026
  • Closed Interval Overlap QueriesONSITE INTERVIEW · Seen Aug 2026
  • Movie Billboard RotationONSITE INTERVIEW · Seen Jul 2026
  • Command Undo Data StructureONSITE INTERVIEW · Seen Apr 2026
  • Repeated Titles in Viewing HistoryPHONE SCREEN · Seen Sep 2026
  • Capacity-Limited Timed CachePHONE SCREEN · Seen Sep 2026
  • Convert Sparse Records to a Filled TableOA · Seen Sep 2026
  • Sparse Matrix MultiplicationOA · Seen Sep 2026

Similar questions at other companies

  • Code Editor FoldingJane Street · ONSITE INTERVIEWJane Street interview questions
  • Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
  • Transactional In-Memory RedisHashiCorp · ONSITE INTERVIEWHashiCorp interview questions
  • Key-Value Store with Nested TransactionsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Bank Accounts With UndoCapital One · ONSITE INTERVIEWCapital One interview questions
  • Implement a Queue Using Two StacksAmazon · ONSITE INTERVIEW
  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
  • Undo/Redo Timeline State EngineKickdrum · OA
All Netflix interview questionsSee Netflix hiring insights
Saved
class Solution {
    public String[] runUndoRedoHistory(String[][] operations) {
        // write your code here
    }
}
Checking account…