← All problems
Next Greater Element I
For each element in nums1, find its next greater element in nums2 (nums1 subset of nums2).
Complexity
Time O(n+m), Space O(n)
Common pitfalls
- Brute force per query O(n*m)
- Forgetting the -1 default
Your solution
Log in to save your code and track progress.