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