C++ || Using Two Priority Queues
Intuition\n - grouping by counting for a greater number\n\n# Approach\n - Using two Priority queues. pq0, pq1\n - pq0 : It doesn\'t have a greater number\n - pq
# Intuition\n - grouping by counting for a greater number\n\n# Approach\n - Using two Priority queues. pq0, pq1\n - pq0 : It doesn\'t have a greater number\n - pq1 : It doesn\'t have second greater number yet\n\n# Complexity\n- Time complexity: O( N log N )\n\n- Space complexity: O(N)\n\n\n# Code\n```\nclass Solution {\npublic:\n    struct node {\n        int val, idx;  \n    };\n    \n    struct compare {\n        bool operator()(const node &a, const node &b) {\n            return a.val > b.val;\n        }  \n    };\n    \n    priority_queue<node, vector<node>, compare> pq0, pq1;    \n    vector<int> secondGreaterElement(vector<int>& nums) {\n        int n = nums.size();\n        \n        vector<int> ans(n, -1);\n        \n        for (int i=0; i<n; ++i) {\n            while(!pq1.empty() && pq1.top().val < nums[i]) {\n                ans[pq1.top().idx] = nums[i];\n                pq1.pop();\n            }\n            \n            while(!pq0.empty() && pq0.top().val < nums[i]) {                \n                pq1.push(pq0.top());\n                pq0.pop();\n            }\n            \n            pq0.push({nums[i], i});\n        }\n        \n        return ans;\n    }\n};\n```
['C++']