Divisible Subarrays

All Testcases not passing.

hello @Anaghajain
a)
image

use long long here

b)
image

it should be
sum=(sum+a[i])%n

1 Like

image
sir, Why is the 2nd statement needed?

sum=(sum+a[i])%n this line is used to ensure that value of -n < sum < n

after that sum=(sum+n)%n statement is used to ensure that value of sum >=0 and sum<n

1 Like

Oh okay! Thank you!!!

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.