C++| Priority_Queue
\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& nums) {\n        unordered_map<int,int>Parent;\n        stack<int>s;\n        vec
```\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& nums) {\n        unordered_map<int,int>Parent;\n        stack<int>s;\n        vector<int>ans(nums.size(),-1);\n        for(int i=0;i<nums.size();i++)\n        {\n            if(s.empty()||nums[s.top()]>=nums[i])\n            {\n                s.push(i);\n            }\n            else\n            {\n               while(!s.empty() and nums[s.top()]<nums[i])\n               {\n                   ans[s.top()] = i;\n                   s.pop();\n               }\n                s.push(i);\n            }\n        }\n        vector<int>store(nums.size(),-1);\n        priority_queue<pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,greater<pair<pair<int,int>,int>>>pq,pq1;\n        for(int i=0;i<nums.size();i++)\n        {\n            while(!pq.empty() and nums[pq.top().first.second]<nums[i])\n            {\n                if(pq.top().second==i)\n                {\n                    pq1.push(pq.top());\n                    pq.pop();\n                }\n                else\n                {\n                    store[pq.top().first.second] = nums[i];\n                    pq.pop();\n                }\n            }\n            if(ans[i]!=-1)\n            pq.push({{nums[i],i},ans[i]});\n            while(!pq1.empty())\n            {\n                pq.push(pq1.top());\n                pq1.pop();\n            }\n        }\n        \n        return store;\n            \n    }\n};\n```
['C', 'Heap (Priority Queue)']