1, 2, ..., limit arrive one at a time in increasing order. You have an empty stack and two operations:
- "Push": take the next number from the stream and put it on top of the stack;
- "Pop": remove the number on top of the stack.
The stack, read from bottom to top, must end up equal to the strictly increasing array wanted. As soon as that happens, you stop: no more operations and no more numbers read from the stream.
Return the sequence of operations that produces wanted.wanted=[2, 3], limit=4 → ['Push', 'Pop', 'Push', 'Push']
Take 1 and remove it right away, then push 2 and 3. The stack is now [2, 3], so we stop and never read 4.
wanted=[1, 4], limit=4 → ['Push', 'Push', 'Pop', 'Push', 'Pop', 'Push']
1 stays, 2 and 3 are pushed and popped at once, then 4 is pushed.
wanted=[1, 2, 3], limit=3 → ['Push', 'Push', 'Push']
wanted is strictly increasingwanted=[2, 3], limit=4
['Push', 'Pop', 'Push', 'Push']
Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.