CT013

Max Stack of Glyphs

MediumAcceptance: 0.0%

The Codetikki masons stack glyphs one on top of another. They need a special stack that, in addition to push and pop, can return the maximum value currently in the stack ÔÇö all in constant time. Implement a max stack with operations: push x (push value x), pop (remove and print top), max (print current maximum). Input: first line n (number of operations), then n lines each containing an operation. Output: results of pop and max operations, one per line.

Example 1:

Input: 5 push 5 push 1 push 3 max pop
Output: 5 3

Example 2:

Input: 4 push 2 push 8 max pop
Output: 8 8

Constraints:

1 <= n <= 10^5 -10^9 <= x <= 10^9 No pop or max on empty stack

Tags:

stack design data-structures
Loading...
Test Cases:No test cases
No test cases available.