← All problems

Next Greater Element I

Easy stacksmonotonic-stackhash maps LeetCode ↗
For each element in nums1, find its next greater element in nums2 (nums1 subset of nums2).

Hints (0/3 revealed)

Log in to reveal hints progressively.

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.