Confuse with this code

https://hack.codingblocks.com/contests/c/89/266
https://ide.codingblocks.com/s/65404
Lecture link :https://youtu.be/QQQpOa3aXew

As per the lecture we need to compute cumm sum first…In line number 19 cumm sum is being calculated but in the following lines we just update these value and directly compute frequency…So in next iteration another number got added and frequency is computed…

here we are not computing cumm sum for all array…so how it is working

Hi Gaurav, this is because we have to deal with remainders of the nos. for example:

// Input
1
5
1 2 3 4 5

Now
the cumulative sum array becomes:

1 3 6 10 15

the array that will be formed in given code is:

1 3 1 0 0

which is same as :

1%5 3%5 6%5 10%5 15%5
= 1 3 1 0 0

Hence, this does not make any difference if you do MOD operation at end or alongwith an operation. We just want to deal with the remanider so we neglect the multiple values.

Hope this helps :slight_smile:

Hey Gaurav, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.

I am sorry…I am about to mark it