Next Greater Element I
Easy · Stack & Monotonic Stack · about 10 minutes
Asked at Amazon, Google, Microsoft, Meta, Bloomberg, Two Sigma.
nums1 is a subset of nums2, and all values are distinct. For each x in nums1, find the first value to the right of x in nums2 that is greater than x, or -1 if there is none. Return the answers in nums1's order.