As reported: Goldman Sachs Analyst Superday, DSA round with two interviewers (Bangalore, 2025): a max-stack variant of Min Stack.
Design a stack supporting push(x), pop(), top(), peekMax() and popMax() (removes the largest element; if several, the one closest to the top).
This is LeetCode 716 — Max Stack.
Example 1
ops = ["MaxStack","push","push","push","top","popMax","top","peekMax","pop","top"], args = [[],[5],[1],[5],[],[],[],[],[],[]]
-> [null,null,null,null,5,5,1,5,1,5]
Constraints: at most 10^5 calls; -10^7 ≤ x ≤ 10^7; pop, top, peekMax, popMax are called on a non-empty stack.
Code runner format: LeetCode's design format: the first line lists the calls (starting with the constructor MaxStack), the second line their arguments; implement the class MaxStack; the harness prints one JSON array with each call's result (null for calls that return nothing).