Easy C++ Solution || (Single Pass Solution) ✅✅
Code\n\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& nums) {\n        int n=nums.size();\n        vector<int> ans(n,-1);\n      
# Code\n```\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& nums) {\n        int n=nums.size();\n        vector<int> ans(n,-1);\n        stack<pair<int,int>> st;\n        priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n        for(int i=0;i<n;i++){\n            while(!pq.empty() && pq.top().first<nums[i]){\n                int j=pq.top().second;\n                ans[j]=nums[i];\n                pq.pop();\n            }\n            while(!st.empty() && st.top().first<nums[i]){\n                pq.push({st.top().first,st.top().second});\n                st.pop();\n            }\n            st.push({nums[i],i});\n        }\n        return ans;\n    }\n};\n```
['Heap (Priority Queue)', 'Monotonic Stack', 'C++']