C++||solution using heap||Easy solution
Intuition\nAs we need to sort elements by their frequency,we can simply use priority queue to do so.\n\nBefore looking at the solution you can try solving https
# Intuition\nAs we need to sort elements by their frequency,we can simply use priority queue to do so.\n\nBefore looking at the solution you can try solving https://leetcode.com/problems/sort-characters-by-frequency/ with priority queue to be more clear!!\n\n# Approach\nwe can customise cmp class to maintain max heap based on frequencies,then simply push them untill heap get empty and return the ans array.\n\n# Complexity\n- Time complexity:\nO(NlogN)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass cmp{\n    public:\n    bool operator()(pair<int,int> p,pair<int,int> q){\n         if(p.second == q.second){\n            return p.first < q.first;\n         }\n         return p.second > q.second;\n    }\n};\nclass Solution {\npublic:\n    vector<int> frequencySort(vector<int>& nums) {\n        priority_queue<pair<int,int>,vector<pair<int,int>>,cmp>pq;\n          unordered_map<int,int>mp;\n          for(auto i:nums){\n            mp[i]++;\n          }\n          for(auto &it:mp){\n             pq.push({it.first,it.second});\n          }\n          nums.clear();\n          while(!pq.empty()){\n            int count = pq.top().second;\n            int ele = pq.top().first;\n            while(count--){\n                nums.push_back(ele);\n            }\n              pq.pop();\n          }\n          return nums;\n    }\n};\n```
['Hash Table', 'Heap (Priority Queue)', 'C++']