This is my code. I am unable to debug it
Divisible subarrays showing run error for 3 test cases
@tanjuljain19
Here is the sum can also be negative as it is given |Ai| <= 10^9, so it will try to access negative index in your code, for this you can use something else like map.
Also check your code when freq[0] = 1 which means the directly divisible by n only once. then in that case (m*(m-1))/2 is zero, so manually add that.
Hope it 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.
this is because of line no 16
here you write
sum%=n;
freq[sum]++;
sum may be negative so you are accessing arr with negative index so it will definetly give run error
to avoid this you can use this
sum=((sum%n+n)%n);
i hope you understand
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.