Kindly tell the problem in my code

problem link
https://hack.codingblocks.com/app/practice/6/1065/problem

code link

hello @laksh.rustagi12
a)
u are never considering prefix array in ur code
b) ur code time complexity is O(N^2) becuase of that it will show tle.

refer this ->

could you elaborate what you mean by prefix array?
please also tell me the expected time complexity

all subarrays whose starting index is 0 are prefix array

I have considered all subarrays haven’t I?

kindly tell me the expected time complexity as well

no u havent
ss

the index i is never considered in the subarray and minimum value of i is 0. so all subarray that are starting from 0 are never considered only index 1 onwards are their in ur solution.

O(n)

kindly take a look at this code and tell me this does not include the prefix subarray.

code link


it does…

the same logic I had used in the original code also but you are saying that it does not.
please elaborate on the problem in that code except for the time complexity issue

in ur original code .

i is not the starting index.as per ur logic the starting index of array is i+1.

what should be the modification in the code to solve it?

in lin 26 ,u should use i-1 in place of i.

also take care of corner case where i is 0 .
for such case no need to subtract anything ,just check cumsum[j]%n

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.