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.
segmentation fault is occuring. what is the error?
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.
segmentation fault is occuring. what is the error?
That’s because your are not taking input N, also size of your array should be 100000 as number can be in this range.
That’s because of wrong logic, it’s reading same subarray many times,
These are your calculated subarray and you can see values are getting repeated. There might be a hint video attached for this problem in your course. Would recommend you to see it.
I: 0 & J: 1
I: 0 & J: 1
I: 0 & J: 2
I: 0 & J: 2
I: 0 & J: 2
I: 0 & J: 3
I: 0 & J: 3
I: 0 & J: 3
I: 0 & J: 3
I: 0 & J: 4
I: 0 & J: 4
I: 0 & J: 4
I: 0 & J: 4
I: 0 & J: 4
I: 1 & J: 2
I: 1 & J: 2
I: 1 & J: 3
I: 1 & J: 3
I: 1 & J: 3
I: 1 & J: 4
I: 1 & J: 4
I: 1 & J: 4
I: 1 & J: 4
I: 2 & J: 3
I: 2 & J: 3
I: 2 & J: 4
I: 2 & J: 4
I: 2 & J: 4
I: 3 & J: 4
I: 3 & J: 4
It must be giving you TLE cause of O(N^2) time complexity, O(N) time complexity is discussed in video tutorial. You have applied brute force. Now Implement it the way discussed in video.
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.