Monotonic Stack

Next Greater Element: maintain decreasing stack, pop when greater found. LC 496, 739, 84, 85.

Unvisited
Current element
In stack
NGE found
No NGE (-1)

Controls

Time: O(n) | Space: O(n)

Steps