Loading...
Loading...
Loading...
A notes app keeps the words you typed. TYPE word adds a word at the end and UNDO removes the most recent word still in the note. An UNDO on an empty note does nothing. Print the final note.
TYPE <word> or UNDO.EMPTY if the note has no words.Example
Input
5 TYPE hello TYPE big TYPE world UNDO UNDO
Output
hello
Undo removes world, then big.
Try the problem first. Open one hint at a time.
Treat the note as a stack: push a word on TYPE, pop on UNDO, but only when the stack is not empty.
A stack iterates from the top. Use descendingIterator() to read it from the bottom, in typing order.
Print EMPTY when the stack is empty.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor