Simple Java Solution Using HashMap and Comparator
\nclass Solution {\n    public int[] frequencySort(int[] nums) {\n        HashMap<Integer,Integer> hm=new HashMap<>(); //Creating frequency map\n        for(int
```\nclass Solution {\n    public int[] frequencySort(int[] nums) {\n        HashMap<Integer,Integer> hm=new HashMap<>(); //Creating frequency map\n        for(int x : nums)\n        {\n            if(hm.containsKey(x))\n            {\n                hm.put(x,hm.get(x)+1);\n            }\n            else\n            {\n                hm.put(x,1);\n            }\n        }\n        Integer arr[]=new Integer[nums.length]; //since comparator cant be applied to primitive types\n        for(int i=0;i<nums.length;i++)\n        {\n            arr[i]=nums[i]; //boxing\n        }\n        Arrays.sort(arr,new Comparator<Integer> ()\n                    {\n                        @Override\n                        public int compare(Integer a , Integer b)\n                        {\n                            if(hm.get(a)> hm.get(b))\n                                return 1;\n                            else if(hm.get(a)<hm.get(b))\n                                return -1;\n                            else\n                                return b-a;\n                        }\n                    });\n        for(int i=0;i<nums.length;i++)\n        {\n            nums[i]=arr[i]; //unboxing\n        }\n        return nums;\n    }\n}\n```\n\n**Please Upvote If It Helps**\n**Happy Coding : )**
['Java']