Use of MOD in the answer

In the solution, we have first checked for number of ways from the left and then used mod on it. Then when we check for number of ways from the top, we add the previous value and the no. of ways from top but we do not
take mod of the number of ways from top rather do it for the total. So wouldn’t the expression become

(left%MOD + top)%MOD and shouldnt it be

(left%MOD + top%MOD)%MOD??

Hello @tusharnitharwal, this doesn’t matter as far as the value doesn’t get overflow. As if you have studied about the properties of modulo operator then mod is distributed among the nos. if we are doing multiplication or addition or subtraction.
Like :
(a+b)%mod = (a%mod+b%mod)%mod
but we can also say
that
(a+b)%mod = (a%mod+b)%mod or (a+b)%mod = (a+b%mod)%mod but this is true as far as the values doesn’t get overflow. Although pls try to use this (left%MOD + top%MOD)%MOD.
It ensures the chances of the error will be very very less as it will make both the values smaller than mod.
I hope it is clear to you. In case it is clear to you pls mark it as resolve and provide the rating as well as feedback so that we can improve ourselves.
In case there is still some confusion pls let me know, I will surely try to help you out.
Thanks :slight_smile:
Happy Coding !!

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.