FunctionRacerProblemsRace

Next Greater Element

EasyStacks and queuesPython, JavaScript, TypeScript, Java, C++

All values in nums2 are different, and every value of nums1 also appears in nums2.

For each x in nums1, find x in nums2 and look to its right: return the first value that is bigger than x, or -1 if there is none. Give the answers in the order of nums1.

Example 1

nums1 [4,1,2]
nums2 [1,3,4,2]
returns [-1,3,-1]

Right of 4: nothing bigger (-1). Right of 1: 3. Right of 2: nothing (-1).

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems