dsa · easy

Next Greater Element I

GreyOrangeArrayStackHash MapFoundation

nums1 is a subset of nums2. For each value in nums1, find the first greater element to its **right** in nums2 (or -1).

Arguments

**Example:** nums1=[4,1,2], nums2=[1,3,4,2][-1,3,-1].

Constraints

1 <= nums1.length <= nums2.length <= 1000 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[4,1,2]
[1,3,4,2]

Expected:
[-1,3,-1]

Example 2

Input:
[2,4]
[1,2,3,4]

Expected:
[3,-1]

Open in the Dojo editor