One testcase failing

run time error in testcase zero. i cant figure out why

Hi @itida_99
Run time error in your code is because of array initializing. You have fixed the size of array as 4. Instead you should take array as a[n] after taking input n from user. After that you are computing sum considering size of subarray only as 1, 2, and 3 but if n>=4 sum 0 can be achieved in a subarray of size more than 3. For example : when n is 6 and a[6]={-1, 2, 3, -7, 2} sum is 0 if we consider last 4 elements.

You have to use the following approach :

  1. Calculate the prefix sum of the array
  2. Then there are 2 conditions when there is sub array with sum 0 that is when element of prefix sum
    1). Either repeats or
    2). Or prefix it is 0.

but the question specifies that 1<=n<=4

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.