Doubt in line sum=(sum+n)%n of code

if value of sum is greater than value of n in -ve then adding n to it will also make sum still -ve i cannot understand this line

no if suppose that result is -2 and if you add n to it i.e5 then -2+5 is 3 which is positive .
if you have any other doubt you can ask here .
Happy Learning !!

i mean if n=5 and sum=-7 then sum + n =-2 .so sum will still be -ve only .so why do we add n to sum then

here you are assuming this case yourself or this is the sample case somewhere in the case.
because we are taking mod of sum with n i guess so sum will never be greater then n .
so i dont think this could be the case which can arise .

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.