Next Greater Element I — JavaScript easy interview problem
The next greater element of some element x in an array is the first greater element to the right of x. You are given two distinct 0-indexed arrays `nums1` and `nums2` where nums1 is a subset of nums2. For each nums1[i], find the next greater element in nums2. If none, use -1. Return an array ans of length nums1.length.
Tags: stack, monotonic
Practice this Arrays problem free in the JS Interview Playground with automated tests and unlockable solutions.