Search
⌘K

Leetcode 496. Next Greater Element I

Given nums1 as a subset of nums2, for each element in nums1 return the first greater element that appears to its right in nums2 (or -1 if none). This is typically solved by precomputing next-greater values for nums2 using a monotonic stack to get an O(nums1.length + nums2.length) solution.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.