you said this code works for -ve sums too.
Then why it fails if i take array as -10, -5, 5, 2, 1 .
Explain the line "sum=(sum+n)%n"
hello @alok.maurya
first u need to convert sum in between range of -n to n
for that first take mod of sum with n
i.e sum=sum%n;
now use mod property ->
sum=(sum+n)%n -> // this is done to make mod positive
if u add these two lines then ur code will work for evry cases
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.