Why we are setting freq[0]=1;

i don’t understand this in the code.

@premang
it is done to handle all subarray starting from index 0.

for example
consider mod cumulative sum is
1 2 3 0 4 5 6 6.

here if u see 0 is there that means from index 0 ,to index 3 sum is divisible by n.
now if we initialise freq[0]=1 then freq[0] total count will be 2.
and using formula 2*(2-1)/2 = 1 we get 1 which is correct.
but if we dont initialise freq[0] with 1 then freq[0] total count will be 1.
and using formual 1*(1-1)/2 =0 we get 0. which is wrong .

i dont understand anything.
to be specific
mod cumulative sum,
1 2 3 0 4 5 6 6.
if we dont get sum%n ZERO then why we are storing freq[0]=1. That is totally wrong.

see if we dont get any sum%n zero inside our array then freq[0] contribution in our answer will 0.
because freq[0] * ( freq[0]-1 ) / 2 => 1 * (1-1) / 2 => 0.

clearly it will not affect our answer.

but if there exist some sum%n zero then freq[0]=1 initialisation plays an important role.
please watch this -> https://www.youtube.com/watch?v=p5Cm_r4T1Rw
and dry run the code on some testcase.

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.