Why is my code showing runtime error

Hey
The problem is you are maintaining a range of 256 only but as per constraints:
1<=N<=10^6
0<=Ai<=10^6
This means either keep range as 10^6 or find maximum from array and maintain count array as
int count[max+1];
For your convenience:
int max=INT_MIN;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]>max)
max=a[i];
}

countingSort(a,n,max);

You can do this .
Also coming to your second for loop in countingSort function remember to run it till max+1 or range+1 i.e
for(int i=0;i<max+1;i++)
Otherwise again you will face runtime error.
Try to do these changes and run your code and let me know for further doubts. If they have been resolved dont forget to mark your doubt as resolved!!

still the problem persists. Runtime error. I made the changes

I made the changes to your code and ran and it passed.
Okay no problem just pass on the link to your updated code!
I will look into it

As you are not replying


This is the code of yours that i corrected.
Read the comments carefully and let me know if there is any doubt!

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.