DIVISIBLE SUBARRAYS question doubt

Last test case is showing wrong answer. Please help.

@Rooopak_Sharma
Your code requires two modifications.
In Line No.32 , the for loop condition should be modified from i<n && fre[i]!=0 to i<=n.
This is because there might be array indices in freq array that still have frequency 0. Your loop would stop there and wouldn’t consider all cases.

The second change is to be made in Line No.26. Even though you are taking the modulo right in the next line , you should also take in this line as well since the sum value could get so large that you might end up with the wrong answer after adding n.
Also , alternatively the spec value could also get extremely low in case of negative array values that adding n to it to make it positive wouldn’t make work and you would still get wrong answer. So take modulo in both Line no 26 as well as 27 .
Modify line no 26 to
spec = (spec + a[i]) % n ;