Next Bigger Neighbor

L4 Easy Stack
Concept
A monotonic (here, decreasing) stack answers "next greater element" questions for every index in a single right-to-left pass.
Given an array nums, return an array where the value at each position is the next element to its right that is strictly greater than the value at that position, or -1 if no such element exists.
Examples
▸ nums = [4, 1, 2]
→ [-1, 2, -1]
▸ nums = [1, 3, 2]
→ [3, -1, -1]
▸ nums = [5, 4, 3, 2, 1]
→ [-1, -1, -1, -1, -1]
Progressive Hints
Hint 1 · Nudge
Think right to left, so the answer for each element is the nearest bigger value already seen.
Hint 2 · Plan
Scan from right to left keeping a stack of candidate values in increasing order. For each element, pop any candidate that is not strictly greater than it; the value now on top is its answer, or -1 if the stack is empty. Then push the element.
Hint 3 · Approach
result = array of -1, stack = []. For i from the last index to 0: while the stack is non-empty and its top is at most nums[i], pop; set result[i] to the stack's top or -1; push nums[i]. Return result.
Output
// Run your code to see the output here.