beats 95% of users
Intuition\ncounting sort approach\n\n# Approach\n-50000 is min possible value in array \n50000 is max possible value in array\n\ncreating a new cnt array of siz
# Intuition\ncounting sort approach\n\n# Approach\n-50000 is min possible value in array \n50000 is max possible value in array\n\ncreating a new cnt array of size 50000+50000+1\nto store all counts of elements\n\nfor(int i=-50000 ; i<=50000 ; i++)\nvalues may be negative also\n \nsorting based on count values\n\n# Complexity\n- Time complexity:\nO(N) where N is range of numbers in array\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> sortArray(vector<int>& nums)\n    {\n        int n  = nums.size() ;\n        int a = 50000 ;\n        int b = -50000 ;\n\n        vector<int> cnt(100001,0) ;\n        for(int i=0 ; i<n ; i++)\n        {\n            cnt[nums[i]+50000] ++ ;\n        }\n        int idx = 0 ;\n        for(int i=-50000 ; i<=50000 ; i++)\n        { int c = cnt[i+50000] ;\n            for(int j=0 ; j < c ; j++)\n            {\n                nums[idx++] = i  ;\n                \n            }\n        }\n        return nums ;\n        \n    }\n};\n```
['Counting Sort', 'C++']