C++ || Map and Priority Queue
Approach: Use an unordered map for storing frequency of numbers present. Then, a priority queue with custom comparator class is used to store the numbers accord
Approach: Use an unordered map for storing frequency of numbers present. Then, a priority queue with custom comparator class is used to store the numbers accordingly. Here is the code implementation.\n\n```\nclass compare{\n    public:\n    bool operator()(pair<int,int> n1, pair<int,int> n2){\n        if(n1.second==n2.second){\n            return n1.first<n2.first;\n        }\n        return n1.second>n2.second;\n    }\n};\n\nclass Solution {\npublic:\n    vector<int> frequencySort(vector<int>& nums) {\n        vector<int> res;\n        unordered_map<int,int> m;\n        for(int i=0;i<nums.size();i++){\n            m[nums[i]]++;\n        }\n        \n        priority_queue<pair<int,int>, vector<pair<int,int>>, compare> pq;\n        for(auto x: m){\n            pq.push({x.first, x.second});\n        }\n        \n        while(!pq.empty()){\n            while(m[pq.top().first]>0){\n                res.push_back(pq.top().first);\n                m[pq.top().first]--;\n            }\n            pq.pop();\n        }\n        return res;\n    }\n};\n```\n\n**Please upvote!**
['C', 'Heap (Priority Queue)']