very simple using 2 stack;l
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& arr) {\n        stack<int>st1,st2,temp;\n        int n =arr.size();\n        vector<int>ans(n,-1);\n        for(int i=0;i<n;i++){\n          while(!st2.empty()&& arr[st2.top()]<arr[i]){\n              ans[st2.top()] = arr[i];\n              st2.pop();\n          }\n          while(!st1.empty()&&arr[st1.top()]<arr[i]){\n              temp.push(st1.top());\n              st1.pop();\n          }\n          while(!temp.empty()) {\n              st2.push(temp.top());\n              temp.pop();\n          }\n          st1.push(i);\n        }\n    return ans;  \n    }\n};\n```
['C++']