Divisible Subarray problem

Can u pls explain why runtime error is coming
when I removed sum%=n; from code runtime error is coming but according to me sum%=n;
and sum=(sum+n) % n are same

Hello Sulbh,
sum%=n is equivalent to sum=sum%n

in general if op is any operator then
a (op)=b is equivalent to a=a(op)b
I hope this will clear your doubt
regards
Aman yadav

you were getting run error because of integer overflow.
I have added one line of code to prevent overflow (line number 20).
Now your code works fine.

regards
Aman yadav

I was saying when we are writing sum=(sum +n) %n then there will be no need of writing sum=sum%n?

1 Like

Yeah no need to take modulo again.

@sulbh579 hey sulbh if your doubt is cleared now then please mark it resolved from your side