in the divisible subarray problem,in number system portion why are we adding sum=sum+n%n condition always if it is only for negatve numbers??
In the divisible subarray problem,pigeon hole principle
hello @sneha23
yeah it is done to avoid negative values and to ensure that sum always stay in range [0,n)
the property that we are applying is this->
( a-b) %mod = (a -b + mod) %mod ;
but why sir has added both the cases then it does have been under if else isnt??
first when bhaiya did
sum%n after adding a[i] to it.
that will ensure value of sum in range [-(n-1) …n-1]
now we want only non negative values for that we added n to it so the new range will be [ 1 … 2n-1]
and then did %n again to make it in range [0 , n)
alright thanx!!
understood
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.