Min Stack (Design)
Design a stack that supports push, pop, top, and retrieving the minimum element, all in O(1). Write createMinStack() returning an object with:
push(x), pushx.pop(), remove the top.top(), return the top without removing it.getMin(), return the current minimum.
The trick: alongside the main stack, keep a second "min stack" whose top is always the current minimum, so getMin never has to scan.
const s = createMinStack();
s.push(-2); s.push(0); s.push(-3);
s.getMin(); // -3
s.pop();
s.top(); // 0
s.getMin(); // -2