here is the question: (CodeChef)

I used the logic that while adding I can continuously check if the sum is even or odd, if it’s even ill save the length that it was even in, so like this in the end ill get the maximum length where it was even.

but I am somehow getting the answer wrong. here is my code:-

I also tried putting custom inputs, but got all correct outputs in those, I don’t know where I am going wrong, so would be helpful if you tell me, thanks!

Hi, consider the input:

```
2
2
6
```

The correct answer would be

```
1
5
```

since the subarray: [2] has an even sum and the subarray [2,3,4,5,6] has an even sum.

Your program outputs

```
0
4
```

hello! sorry for replaying late, i thought that we had to start from 1. so my understanding of question was wrong as i thought the maximum series whose sum is even had to start from 1.

thank you for your help!

1 Like

My code is also similar to yours for “Maximum length even subarray” But i didnot understand the logic.Can you explain?