NZEC error Java ZCO14002

I am using Java and getting NZEC runtime error for task1 all remaining tasks are AC. link to my code:link text
But able to clear all tasks using C.
What is wrong in my java code?
TIA

1 Like

As far as I can see, it appears to be a problem of the test case. Apparently the length of the array in the input is not always equal to the input value of N. Here is a version of your code (link) that gets AC by keeping track of the number of integers in the input instead of using the given value of N.

n = int(input())
c = [int(x) for x in input().split()]
if len(c) <= 3:
    print(min(c))
else:
    cost = [c[0],c[1],c[2]]
    for i in range(3,len(c)):
        cost.append(c[i] + min(cost[i-3:i]))
    print(min(cost[len(c)-3:]))

Here this pass all test cases there is a problem in test case, there the give value of n but the element they have given in next line, they are greater or lesser then value of n

Access is denied to that link. We cannot access your code. Either paste your code here or give a link to ide. For ZCO, usually you cannot give link to your solutions.

1 Like

Rather than pasting your code here, paste your code on text storing sites like pastebin.com or ideone.com and share that link here. But make sure that its public otherwise others won’t be able to see it.

Updated code link.

Thanks you