class Solution {
public:
vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {
stack<int>s;
unordered_map<int,int>q;
vector<int>w(nums1.size());
for(int i=nums2.size()-1;i>=0;i--){
while(!s.empty()&&nums2[i]>=s.top()){
s.pop();
}
q[nums2[i]]=s.empty()?-1:s.top();
s.push(nums2[i]);
}
for(int i=0;i<nums1.size();i++){
w[i]=q[nums1[i]];
}
return w;
}
};