Next Greater to the Right — Solution & Editorial
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)
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)