nums2
array:
a. While the stack is not empty and the current element is greater than the stack's top element, pop the stack and update the hashmap with the popped element as the key and the current element as the value.
b. Push the current element onto the stack.-1
as the value.nums1
array and for each element, look up the next greater element in the hashmap and add it to the result list.