You are given two distinct 0-indexed integer arrays nums1 and nums2, where nums1 is a subset of nums2.For each element in nums1, find the next greater element in nums2 and return as an array.The brute-force solution has a time complexity of O(m × n), but a better approach using a monotonically decreasing stack reduces it to O(m + n).The algorithm involves utilizing a stack to efficiently find the next greater element and mapping the results to nums1.