Its showing correct answer in custom output.
Here’s the link to my code:
Showing wrong answer in Counting Sort
Hi @Pranshu_gupta, the problem here is due to confusion with indices. Pls check your line no. 11, 14, 17.
We here are assuming that frequency array’s 0th index will contain count of min element i.e. b and similarly 1st index will contain frequency of b+1.
So we carefully need to fill and acess the freq array as we have assumed index to be starting from b.
In line no. 14, if we have to increment value of frequency of b then freq[0] shoud be ++'d you’ve written:
freq[a[i]]++;
Correction is
freq[a[i]-b]++;
now for incrementing freq of b it will increment freq at 0th index as b-b = 0. Hope you got it.
Next is in line 14. We know max is b and min is c and there are total m nos. in between them inclusive. So we need to go from i=0 to i<m. and then when rewritting our array we want to put the value b or b+ so we do:
a[j] = b + i ;
There are more ways where we can use different steps to acheive same thing. You just need to know how to play with indices.
Just make these 3 changes and your program will work fine then.
Hope this helps 
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.