Monotone stack application
Previous larger element
For every input element a[i], the algorithm finds its rightmost preceding element with a strictly larger value.
Big step one item
Shift + ← →
Small step one operation
← →
Stack
READY
in stack
current
being removed
Pseudocode
for i = 1 … n while S not empty and S.top ≤ a[i] S.pop() b[i] = S.empty ? ∅ : S.top S.push(i)