Back

Undo/Redo Task List

medium

Streak

0 days

Progress

0%

Submitted

0

Undo/Redo Task List

React35 minmediumFree

Prompt

Build this React exercise in 35 minutes.

Create a small task list with Add, checkbox toggle, Remove, Undo, and Redo. Start with the two supplied tasks. Store immutable snapshots as past/present/future; keep at most 20 prior snapshots. New task actions after Undo discard the redo branch. Input typing is not a history action. IDs are generated once in the Add event and survive Undo/Redo. This is local state only: no persistence, rich-text editor, keyboard shortcut, API, or collaborative history.

Acceptance checks

  • Add, toggle, and remove each produce one undo step; typing in the input produces none.
  • Undo restores the exact previous task IDs, order, text, and checked states; Redo reapplies it.
  • After Undo, a new task action clears all redo history; blank Add creates no history entry.
  • Undo and Redo are disabled at their boundaries. Empty lists remain usable.
  • Keep at most 20 previous snapshots; undoing and redoing never mutates any saved snapshot. The unsent input draft is independent of history.

Saving a submission records completion; it does not run these manual checks.

Learn and continue

Prerequisite: Immutable state. Work through the React Machine Coding Foundations path to practice related skills in order.

Requirements

  • →Add, toggle, and remove each produce one undo step; typing in the input produces none.
  • →Undo restores the exact previous task IDs, order, text, and checked states; Redo reapplies it.
  • →After Undo, a new task action clears all redo history; blank Add creates no history entry.
  • →Undo and Redo are disabled at their boundaries. Empty lists remain usable.
  • →Keep at most 20 previous snapshots; undoing and redoing never mutates any saved snapshot. The unsent input draft is independent of history.

Starter packet

What the interviewer handed you

Build a bounded local undo/redo history for a task list.

Manual acceptance checks

  • Add, toggle, and remove each produce one undo step; typing in the input produces none.
  • Undo restores the exact previous task IDs, order, text, and checked states; Redo reapplies it.
  • After Undo, a new task action clears all redo history; blank Add creates no history entry.
  • Undo and Redo are disabled at their boundaries. Empty lists remain usable.
  • Keep at most 20 previous snapshots; undoing and redoing never mutates any saved snapshot. The unsent input draft is independent of history.

Likely follow-ups

  • • How would commands differ from snapshots for a large document?
Example
Loading preview...
For the best coding experience, we recommend using a desktop device.
Preparing Sandbox...
Premium interview report

What interviewers score in this build

Use this before reading the code. It tells you what to say, what to test, and where machine-coding candidates usually lose points.

Interview signals

  • History invariants: Undo restores the exact previous task IDs, order, text, and checked states; Redo reapplies it.
  • Branching and limits: After Undo, a new task action clears all redo history; blank Add creates no history entry.
  • Immutable state: Keep at most 20 previous snapshots; undoing and redoing never mutates any saved snapshot. The unsent input draft is independent of history.

Time checkpoints

  1. 1

    0:00: Define past, present, and future invariants.

  2. 2

    10:00: Wire task actions to immutable commits.

  3. 3

    20:00: Implement Undo/Redo and branch reset.

  4. 4

    35:00: Check limits, empty state, and keyboard operation.

Edge-case checklist

Add, toggle, and remove each produce one undo step; typing in the input produces none.
Undo restores the exact previous task IDs, order, text, and checked states; Redo reapplies it.
After Undo, a new task action clears all redo history; blank Add creates no history entry.
Undo and Redo are disabled at their boundaries. Empty lists remain usable.
Keep at most 20 previous snapshots; undoing and redoing never mutates any saved snapshot. The unsent input draft is independent of history.

Common mistakes

  • Mutating a snapshot corrupts several history entries.
SolutionRead-only · Live Preview

Technical Explanation

A history of values

present is the current task array. past ends with the previous array; future begins with the next redo array. Add, toggle, and remove create new arrays without mutating saved tasks.

Move snapshots between stacks

Undo moves present to the front of future and takes the last past snapshot. Redo reverses that movement. At an empty boundary return the same history. Cap past at twenty when committing or redoing.

Branch after Undo

Any new action clears future. Otherwise Redo would overwrite the user's new branch with a stale alternate timeline. Blank input returns before the action, so it neither consumes history nor destroys redo.

Separate event data from state transitions

Create the task ID once in the Add handler. Functional setters operate on the latest history and stay pure. The unsent input is a separate draft; Undo changes tasks without deleting what the learner is currently typing.

Interview Criteria

History invariants

Undo restores the exact previous task IDs, order, text, and checked states; Redo reapplies it.

Branching and limits

After Undo, a new task action clears all redo history; blank Add creates no history entry.

Immutable state

Keep at most 20 previous snapshots; undoing and redoing never mutates any saved snapshot. The unsent input draft is independent of history.

Time Checkpoints

0:00

0:00: Define past, present, and future invariants.

10:00

10:00: Wire task actions to immutable commits.

20:00

20:00: Implement Undo/Redo and branch reset.

35:00

35:00: Check limits, empty state, and keyboard operation.

Streak

0 days

Last active: Sign in to track

Progress

0%

0/0 solved

Submitted

0

Solutions pushed to review history.

More Machine Coding

View all Machine Coding →
Machine CodingMedium

React Tic-Tac-Toe Engine

Machine CodingMedium

Performant Image Slider

Machine CodingMedium

API Search and Render Image

Machine CodingEasy

Accessible React Tabs

Machine CodingMedium

Recursive File Explorer

Machine CodingEasy

Stopwatch

Related hubs

  • All machine coding
  • Frontend machine coding guide
  • React machine coding questions
  • UI coding interview questions
  • React UI interview questions