Mental Model
We want to find how many consecutive days before today had stock prices less or equal to today's price. We use a stack to remember days with higher prices to quickly find the span.
Analogy: Imagine a line of people with different heights. For each person, we want to count how many people before them are shorter or equal in height until we find a taller person. The stack helps us remember the taller people to skip over shorter ones quickly.
Prices: 100 80 60 70 60 75 85 Stack stores indices of days with prices higher than current day Example stack after some steps: [0]100 -> [1]80 -> [5]75 -> [6]85 -> null ā top of stack
