Doubt in divisible subarrays

Only one test case is being passed,while the other one is not passed.
Here is the code

hey @ratulhans, please share the question link.

https://hack.codingblocks.com/contests/c/925/266

hey @ratulhans, not able to acces this link.
Are you taking about this question
DIVISIBLE SUBARRAYS
You are given N elements, a1,a2,a3….aN. Find the number of good sub-arrays.
A good sub-array is a sub-array [ai,ai+1,ai+2….aj] such that (ai+ai+1+ai+2+….+aj) is divisible by N.

Input Format:
The first line contains the number of test cases T. First line of each test case contains an integer N denoting the number of elements. Second line of each test case contains N integers, a1, a2, a3….aN, where ai denotes the ith element of the array.

The code is running fine for first test case but for second it is giving run error

hey @ratulhans, assuming that you are asking for above question only.
It is giving Runtime error because time complexity of your code is O(n^3) and constraints are very high in question. You need to use pigeonhole principle and precompuation to solve this question.
Please watch this lecture once https://youtu.be/QQQpOa3aXew
In case of any query feel free to ask.

1 Like

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.