LECTURE 17 OF 25
Monotonic Stacks
Keep only unresolved candidates in useful order, so many nearest-greater or nearest-smaller queries finish in one pass.
Builds on
Best read after 9. Stacks and Queues — you can still read ahead, but some of this may lean on ideas covered there.