Problems > Next Greater to the Right > Editorial

Next Greater to the Right — Solution & Editorial

Back to the Problem

Monotonic stack of indices with decreasing values: each new element resolves everything smaller on the stack. Every index is pushed and popped once.

Complexity: O(N)