Monotonic stack: why so many “next greater element” problems collapse into one pattern
Monotonic stacks are powerful when you need the first larger or smaller element to the left or right, without rescanning for every position.
Monotonic stacks are powerful when you need the first larger or smaller element to the left or right, without rescanning for every position.
The key question is:
- which older candidates are no longer worth keeping