Concept Flow - Stock Span Problem Using Stack
Start with empty stack
For each day's price
While stack not empty and top price <= current price
Pop from stack
Calculate span: if stack empty -> i+1 else i - top index
Push current day index onto stack
Move to next day
Repeat until all days processed
Return span array
We process each day's price, popping smaller or equal prices from stack to find the span, then push current day index.
