arrayscomplexitystacks
A monotonic stack can find the next greater value
Anonymous
Scan left to right and keep indices whose next greater value hasn't been found yet. When the current value is greater than the value at the top index, it answers that index; pop and repeat, then push the current index. Each index is pushed and popped at most once, so the scan takes O(n) time.
0