Next Greater Element
All values in nums2 are different, and every value of nums1 also appears in nums2.
For each x in nums1, find x in nums2 and look to its right: return the first value that is bigger than x, or -1 if there is none. Give the answers in the order of nums1.
Example 1
nums1 [4,1,2]
nums2 [1,3,4,2]
returns [-1,3,-1]
Right of 4: nothing bigger (-1). Right of 1: 3. Right of 2: nothing (-1).
Constraints
0 <= len(nums1) <= len(nums2) <= 20- Values of
nums2are distinct.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.