Leetcode: 716. Max Stack
The source is in Max Stack since it might be useful in other problems. It was implemented with a stack to efficiently reply to pop
and top
, a heap for peekMax
and popMax
. While top
is \(O(1)\), all other operations are \(O(\log n)\).