Divisible subarrays

in this ques , why we put pre[0]=1 , while making the pre sum array

because initially the sum is 0

can in case we encounter sum 0 then the count increases to 2.

if we are not putting pre[0] = 1 then we are not considering the case when initially the sum is 0

in that situation we are missing out on pairing of indexes which fetches us sum = 0

try working out for example i/p:
3 1 -3 -1

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.