using HashMap || PriorityQueue || beats 98% ||
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(n)\n\n# Code\n```\nclass Solution {\n    class Pair\n    {\n        int num;\n        int freq;\n        Pair(int num, int freq)\n        {\n            this.num=num;\n            this.freq=freq;\n        }\n    }\n    public int[] frequencySort(int[] nums) {\n      HashMap<Integer, Integer>h=new HashMap<>();\n        for(int i=0;i<nums.length;i++){\n            h.put(nums[i],h.getOrDefault(nums[i],0)+1);\n        }\n        PriorityQueue<Pair>pq=new PriorityQueue<>((a,b)->a.freq==b.freq?b.num-a.num: a.freq-b.freq);\n        for(int i: h.keySet()){\n            pq.add(new Pair(i, h.get(i)));\n        }\n        int arr[]=new int[nums.length];\n        int j=0;\n        while(!pq.isEmpty()){\n            int n=pq.peek().num;\n            int f=pq.peek().freq;\n            pq.poll();\n            for(int i=0; i<f; i++){\n                arr[j]=n;\n                j++;\n            }\n        }\n        return arr;  \n     \n    }\n}\n```
['Heap (Priority Queue)', 'Java']