Learning on Web Dev Open is free for all.

Interview Prep · Low Level DesignDesign a text editor with undo
← Low Level Design

Design a text editor with undo

Medium35 minFree, no account

Two stacks and a data structure choice that decides whether it is usable on a large file.


The question

Design the core of a text editor: insert, delete, cursor movement, undo and redo.

It must stay responsive on a 10MB file, and typing twenty characters should undo as one action, not twenty.

Functional
  • Insert and delete at the cursor; select a range and replace it.
  • Unlimited undo and redo.
  • Consecutive typing coalesces into one undoable action.
  • Find and replace.
Non-functional
  • Edits in the middle of a 10MB file must not be O(n).
  • Undo history must not grow without bound in memory.
35:00Commit to an answer before you open the solution. Reading it first teaches you to recognise good answers, which is not the skill being tested.

Stuck?

0 of 3 hints taken

The worked solution

written by a person · not a grade

Score yourself

0 of 5 marked
  • Chose a buffer structure with a stated reason and threshold25
  • Commands that carry their own inverse, including captured deleted text25
  • Two stacks with redo cleared on a new edit20
  • Coalescing rules, including what breaks a run20
  • Bounded history by memory, not entry count10

We run no AI here and nothing on this page grades you. The score is yours, and the useful number is the one you get on the same problem a month from now, cold.

kept in this browser only