✅ C++ ||  🐸 Shortest code ever with Explanation || stack + priority queue
Approach : \n First find the next greater element (nge) using monotonic stack and put the element for which we found n.g.e. let curr to priority_queue( min heap
**Approach** : \n* First find the *next greater element **(nge)*** using monotonic stack and put the element for which we found n.g.e. let **curr** to **priority_queue( min heap )** and the *next greater element **(nge)*** of **curr** to **stack**.\n* These values in pq can be used to further find it\'s ***second next greater element*** from the nums array that we are traversing. \n\n\teg :      Suppose our `pq.top().first = 2` and since it is in pq that means we already have it\'s *next greater element in stack*. Now in the nums if we found a number` nums[i]` which is greater than 2 that means nums[i] is the ***2nd next greater element*** for 2; \n.\nSo, store ` res[pq.top().second] = nums[i];`\n\n```\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& nums) {\n        int n=nums.size();\n        vector<int> res(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            \n            while(!pq.empty() and nums[i] > pq.top().first){\n                res[pq.top().second] = nums[i];\n                pq.pop();\n            }\n            \n            while(!st.empty() and nums[i] > st.top().first){\n                pq.push(st.top());\n                st.pop();\n            } \n            st.push({nums[i],i});\n        }\n        \n        return res;\n    }\n};\n```
[]