LeetCode 155 Min Stack - Why Naive Fails

The trap

Track the minimum in a single variable. Update it when pushing smaller values.

The problem: when you pop the current minimum, how do you know the new minimum? You'd need to scan the entire stack, making pop() take O(n)O(n) time.

How can you remember previous minimums?