✅💯Best Solution in C++ || Similar to Next Greater Element || Stack✔✔
Code\nPlease Upvote if u liked my Solution\uD83D\uDE42\n\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& nums) {\n        stack<in
# Code\n**Please Upvote if u liked my Solution**\uD83D\uDE42\n```\nclass Solution {\npublic:\n    vector<int> secondGreaterElement(vector<int>& nums) {\n        stack<int> st;\n        using pi = pair<int,int>;\n        priority_queue<pi,vector<pi>,greater<pi>> st2;\n        int n=nums.size();\n        vector<int>ans(n,-1);\n        st.push(0);\n        for(int i=1;i<n;i++){\n            while(st2.size()>0 && st2.top().first<nums[i]){\n                ans[st2.top().second]=nums[i];\n                st2.pop();\n            }\n            while(st.size() > 0 && nums[st.top()] < nums[i]){\n                st2.push({nums[st.top()],st.top()});\n                st.pop();\n            }\n            st.push(i);\n        }\n        return ans;\n    }\n};\n```
['Array', 'Monotonic Stack', 'C++']