Next Greater Element — a decreasing stack, scanned backward
Walk nums2 from right to left. The stack holds candidates that are still "unbeaten"; pop any that the current value dwarfs, and whatever remains on top is the current value's next greater element.
Try:
nums2 (scanned right → left)
stack (top = right)
next-greater map
answer for nums1