According to the solution given in the video https://www.youtube.com/watch?v=GMx590YbPQE ,modulus of answer is being taken inside the loop but in the question it is being mentioned that we have compute the modulo on overall profit so modulo should be taken outside the loop.
Why modulus of answer is being taken inside the loop?
@TusHar-AroRa-2294450460870717
hello tushar ,
it is modular arithmetic property
(a1+a2+a3…+an)%mod =(a1%mod+a2%mod + a3%mod …an%mod)%mod
In the video he is using the same property
But,if i am submitting the answer by applying modulus outside the loop then the answer is not getting submitted and giving WA.
yeah because of overflow.
thats the reason we are applying this modulo property so that our sum dont excceds the range.