Counting Sort || O(n) Solution || JAVA
\n# Approach\n- Create an integer map array integer map Array of size mapRange(max - min +2).//(+2 is just to avoid overflow here in mapRange)\n- Traverse whole
\n# Approach\n- **Create an integer map array integer map Array of size mapRange(max - min +2).**//(+2 is just to avoid overflow here in mapRange)\n- **Traverse whole array and store the frequency in the map.**\n- **Again traverse the whole map and put the (index + min(offset here)) in the new sorted Array.**\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(max(mapRange, n))\n\n# Code\n```\nclass Solution {\n    public int[] sortArray(int[] nums) {\n        int n = nums.length;\n        int max = Integer.MIN_VALUE;\n        int min =Integer.MAX_VALUE;\n\n        for(int i: nums){\n            max =Math.max(max, i);\n            min =Math.min(min, i);\n        }\n\n        int[] sortedArray = new int[n];\n        int mapRange = max -min +2;\n        int[] map =  new int[mapRange];\n        \n        for(int i=0; i< n; i++){\n            map[nums[i] - min]++;\n        }\n        int index =0;\n        for(int i=0; i< mapRange; i++){\n            while(map[i]>0){\n                sortedArray[index++] =i+min; \n                map[i]--;\n            }\n        }\n        return sortedArray;\n    }\n}\n```
['Java']