FunctionRacerProblemsRace

Editor With Undo and Redo

EasyStacks and queuesPython, JavaScript, TypeScript, Java, C++

A text editor starts with empty text. commands is a list of strings applied in order:

A new type throws away every word that could still be redone. An undo with nothing to undo and a redo with nothing to redo do nothing. Return the final text with the words joined together with no separator, or "" if it is empty.

Example 1

commands ["type ab","type cd","undo","redo"]
returns "abcd"

ab and cd are typed, undo removes cd, and redo puts it back.

Example 2

commands ["type ab","type cd","undo","type ef","redo"]
returns "abef"

After cd is undone, typing ef discards it, so the final redo has nothing to put back.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems