Decreasing monotonic stack: find the next greater element
Scan the array left to right. Before pushing each value, pop every stack value that is ≤ it, so the stack stays decreasing from bottom to top. Each pop resolves a next-greater-element: the value arriving is the first larger value to the right of the one it pops.