Why all test cases are not passing

hey @uthyasani since x can be zero as well, when you subtract a[x-1] in that case it returns garbage value, instead subtract a[max(0, x-1)], other than that your logic is correct.