Hi,
I’m trying to solve the problem 9.12 and I found almost by myself the trick. Now, I was wondering if it would be even better to apply the same solution as 9.1, basically storing in the deque the number of apparitions together with the possible max element. Large elements tend to accumulate in the head of the deque.
I was hinting at using a queue and a deques, as in 1st solution, instead of 2 stacks.