Next Greater Element (to the right): For each element nums[i]
, find the first element to its right which is strictly greater; if none, return -1.
We use a monotonic decreasing stack of indices: while the current value is greater than the value at the stack top, we can resolve NGE for that top.
Example: nums = [2, 1, 2, 4, 3] → NGE = [4, 2, 4, -1, -1]