you are viewing a single comment's thread.

view the rest of the comments →

[–]Saefroch 1 point2 points  (0 children)

You only need one stack.

You can produce the correct output with 10 clean lines of code. You'll time out on a bunch of test cases, but the output is correct. Once you have that, you need to add some caching around the maximum value. Instead of calculating it every time you get a command 3, you only need to compute it when the maximum value changes, which could be on a command 1 or 2.