Previous Greater Element
The nearest larger value to the left, via a monotonic stack.
Monotonic Stack: Previous greater element
4 is greater than 3, so 4 is the previous greater element of 3. Push 3.
Cost
- Best
- O(n)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(n)
Before this
A variant of
Taught by the same lesson
Monotonic Stack covers these too, in the same run.