arrayscomplexitystacks
a monotonic stack finds the next greater value
Anonymous
Scan from left to right. While the stack top is smaller than the current value, the current value is the next greater value for that stack entry. Push the current index; each index enters and leaves the stack at most once, so the scan takes O(n) time. Keep indices when the output needs positions.
0