nums1 is a subset of nums2 (all values distinct). For each element of nums1, find the first element greater than it appearing to its right in nums2, or −1 if none exists.
Input
nums1nums2Output: the answers for nums1, space-separated.
4 1 2 1 3 4 2
-1 3 -1
Nothing right of 4 is bigger; 3 follows 1; nothing follows 2.
2 4 1 2 3 4
3 -1
Run your code against the sample tests, or Submit to run the full suite.