Typing With Undo
keys is a list of strings describing what was pressed, in order. Each string is either a single lowercase letter, which is typed and added to the end of the text, or the word "UNDO", which deletes the most recently typed letter that is still in the text.
An UNDO when the text is empty does nothing. Return the final text, or "" if nothing is left.
Example 1
keys ["a","b","UNDO","c"]
returns "ac"
a and b are typed, UNDO removes b, then c is typed.
Example 2
keys ["UNDO","x","UNDO","UNDO","y"]
returns "y"
The first UNDO has nothing to delete; x is typed and removed by the next UNDO; the third UNDO has nothing to delete again; then y is typed.
Constraints
0 <= len(keys) <= 100- each item is one lowercase letter or
UNDO
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.