Hi,
So there are problems with the scenario in which the value of the prefix sum becomes negative, u were trying to access -ve array index
Do something like this
sum_arr[i+1]=(sum_arr[i]%n+arr[i]%n+n)%n;
then
for(ll i=0;i<=n;i++)
{
freq[sum_arr[i]]+=1;
}
this has to be corrected, since sum_arr ranges from [0,n] and not [0,n-1]
Also all the data type need to be changed to long long int.
I recommend u watch Prateek bhaiyas video TO optimize the code further
https://admin.codingblocks.online/contents/edit/43/video/17