Doubt in a step

why are we adding mod in the code cant we take the % directly

Hi… can u share the code snippet regarding which u are talking

image

i am talking about the last statement in which we are adding mod

Hi… so we are adding mod to handle negative values

but we are already handling that case in the if condition

that thing is different… there we are checking i-1>=0 because only if i-1>=0 we can subtract pre[i-1] else i-1 would be negative and subtracting pre[i-1] would be give error as we would be accessing negative index.

ok ok i got it now…thanks

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.