why is my code failing testcases when I am eliminating the line sum %=n?Actually I failed to understand the video explanation completely.
Query regarding 1 line of code
We do sum%=n as we only want remainder to occur twice.You could have taken entire sum and then before increasing mod count divide it by n.But that is not a good way to solve.
if we skip that line of code why are test cases not getting passed?
What we are checking is number of times a remainder is coming so say for n=5, 7 and 12 are same but we won’t consider them as same if we don’t take mod by 5.
And why same remainder prefix has sum divisive by true as say from 0 to 2nd index sum is 12 then till 4th index sum is 22 now from 3rd index to 4th sum is 10 divisible by 5. Hence if same remainder appears again then sum from its first occurrence till current index is divisible by n.
pls can you explain me that if instead of sum%=n we are doing (sum+n)%n test cases are not getting passed but when I am writing both the statements then all TCs are getting passed.
Why are TC s not getting passed on writing only (sum+n)%n instead of writing both the statements?
Hey you might be doing some other error as (sum+n) %n=sum%n+n%n which is sum%n as n%n is 0
Also,we do sum+n if remainder comes out to be negative as it can be negative if sum is negative
Pls can you help me out to debug that code if I send the link pls
Yeah sure.
Send the link
I have mentioned the changes and why it is needed in comments.Please see it.
Also,the code is now getting accepted
thnks I have understood the correction.Using the same logic I solved the qstn by taking 1 more array but still it is showing segmentation fault but why i didnt understand.I am sending the code that i made.