Min Stack (LC #155) supports push, pop, top, and getMin all in . Store pairs of (value, currentMin) where currentMin is the minimum at that point. On push, currentMin is min of value and previous top's min. On getMin, return the top pair's min. Uses space. Alternative: use two stacks, only push to the min stack when value is less than or equal to current min. This pattern extends to tracking any monotonic property like max, sum, or product.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/meta-interview-prep/stacks-queues/min-stack
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████████████████████████████████████████████████████████████████████