This is a design problem that tests augmented data structures. Amazon, Google, and Microsoft ask it to see if you can extend standard data structures. The concept applies beyond stacks: you might need a queue with getMin, or a deque with getMax. The principle is the same: track additional state that updates with each operation. Interviewers may ask: "What if we want space?" The trick is to store represented values that let you recover the previous min. This is a harder follow-up.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/stacks/min-stack-why-this-problem
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████████████████████████████████████████████████████████████████████████████████