Reported April 2026
Netflixdesign

Command Undo Data Structure

Reported by candidates from Netflix's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Netflix OA. Under 2s to a working solution.
Founder's read

Netflix asked this in April 2026: design a command system with undo. You're given a state (integer starting at 0), a set of commands that mutate it, and you need to track history so undo reverts the last operation. No redo required. The trick is not the commands themselves. It's the data structure you choose to store state snapshots or operation history. You're looking at a design problem that tests whether you can build a clean abstraction under time pressure. StealthCoder becomes your safety net if the implementation details slip during the live assessment.

The problem

Design a command system that mutates a state and supports undo. Redo is optional. For this problem, the state is a single integer that starts at 0. Supported commands are: Return the output lines produced by the command batch. Function Description Complete the function runCommandUndo in the editor below. runCommandUndo has the following parameter: Returns After adding 5 and multiplying by 3, the state becomes 15. Undo reverts the multiplication, so PRINT outputs 5.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The core pattern here is design with a side of stack usage. You'll typically store either the full state after each command, or store the commands themselves and replay backwards. The first approach (state snapshots) is simpler and less error-prone: push state to a stack before each mutation, pop on undo. The second (command replay) requires reversing logic for each operation type, which is where candidates often make mistakes. Netflix's version caps at a single integer, so snapshots are lightweight. The pitfall is overcomplicating the undo mechanism or failing to handle the command parsing cleanly. Most candidates nail the command execution but botch the stack pop order or forget to track the current state pointer after an undo. Walk through a trace on paper before coding: add 5 (state 5, push 0), multiply by 3 (state 15, push 5), undo (pop 5, state back to 5), print (output 5). That clarity will carry you through.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Command Undo Data Structure cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Netflix's OA.

Netflix reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Command Undo Data Structure FAQ

Do I need to implement redo?+

No, the problem says redo is optional. Focus on undo only. A single stack holding previous states is sufficient. Don't over-engineer.

What's the best way to store history, snapshots or commands?+

Snapshots are cleaner for a single integer. Push the state before each mutation, pop on undo. Less room for reversing logic errors. Commands require you to write inverse operations for each type, which is error-prone.

How do I parse the command batch?+

Treat it as lines of input. Each line is a command (ADD, MULTIPLY, PRINT, UNDO). Parse the number if it's parameterized. Write a simple switch or if-elif chain. Don't overthink parsing.

What happens if undo is called when there's no history?+

The problem doesn't specify, but assume it's invalid input and won't happen, or state stays at 0. Check the examples. If unclear, handle it gracefully (no-op or error) and move on.

Is this problem actually hard?+

No. It's a design test, not an algorithm test. The difficulty is clean code and not second-guessing yourself. Build a stack, mutate, undo by popping. Done in 20 minutes if you don't panic.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Netflix.

OA at Netflix?
Invisible during screen share
Get it