Bucket Sort
I know the answer can be in several lines...but during a real interview, what is the interverer expected to see? More from algorithm level, to evaluate your alg
I know the answer can be in several lines...but during a real interview, what is the interverer expected to see? More from algorithm level, to evaluate your algorithm skills (instead of checking how many default libraries/built-in you can remember)?\n\nHere is a pure bucket sort...\n\n```\nclass Solution {\n    public int[] frequencySort(int[] nums) {\n        if (nums.length == 1) {\n            return nums;\n        }\n        \n        int[] result = new int[nums.length];\n        Map<Integer, Integer> numCountMap = new HashMap<>();\n        int maxCount = 0;\n        \n        for (int num : nums) {\n            int count = numCountMap.getOrDefault(num, 0);\n            count++;\n            maxCount = Math.max(maxCount, count);\n            numCountMap.put(num, count);\n        }\n        \n        List<Integer>[] bucket = new List[maxCount + 1];\n        \n        for (Map.Entry<Integer, Integer> entry : numCountMap.entrySet()) {\n            int num = entry.getKey();\n            int count = entry.getValue();\n            \n            List<Integer> tempList;\n            \n            if (bucket[count] == null) {\n                tempList = new ArrayList<>();\n            } else {\n                tempList = bucket[count];\n            }\n            \n            tempList.add(num);\n            bucket[count] = tempList;\n        }\n        \n        int p = 0;\n        for (int i = 1; i <= bucket.length - 1; i++) {\n            List<Integer> list = bucket[i];\n            if (list != null) {\n                Collections.sort(list, Collections.reverseOrder());\n                for (Integer num : list) {\n                    int count = i;\n                    while(count > 0) {\n                        result[p] = num;\n                        p++;\n                        count--;\n                    }\n                }\n            }\n        }\n        \n        return result;\n    }\n}\n```
['Bucket Sort', 'Java']