What is the need of the frequency array ? and why are we finding Mc2?

why we care about 2 values in same bucket, why don’t we just find (b-a)%n==0 ?

hello @premang
please check this video tutorial by prateek bhaiya->


here he has covered everthing

this is the same video in cb i dont understand anything.

see if we are getting same modulo in prefix sum i,e

…a . . . … … . . a

then that means sum of elements between those two same modulo is divisible by n.
becuase then only
(a+something) %n = a%n
implies something%n=0

so let say we have
…a … a…a…a…
now here if i pick any two a then sum in between them will always be divisible by n.

so if p is the frequency of a in prefix sum array then p*(p-1)/2 such subarray will be there.

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.