Java | Efficient | 1 ms | PriorityQueue | HashMap
\n# Complexity\n- Time complexity:\nO ( n )\n\n- Space complexity:\nO ( n )\n\n# Code\n\nclass Solution {\n    class Pair{\n        int num;\n        int freq;\
\n# Complexity\n- Time complexity:\nO ( n )\n\n- Space complexity:\nO ( n )\n\n# Code\n```\nclass Solution {\n    class Pair{\n        int num;\n        int freq;\n        Pair(int num, int freq){\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```
['Hash Table', 'Heap (Priority Queue)', 'Java']