Hi, this code is for finding the maximum length of sequence in the range N that can give an even sum. When I compile and run its okay but shows error while submitting. I am not able to understand the problem here. Any suggestions?

T = int(input())

for _ in range(T):

N = int(input())

lst = list(range(1,N+1))

while (sum(lst)%2 != 0):

lst.pop(len(lst) - 1)

print(len(lst))

```
T = int(input())
for _ in range(T):
N = int(input())
lst = list(range(1,N+1))
if sum(lst)%2 != 0:
print(N-1)
else:
print(N)
```

try using this code since if the sum of lst is odd then we can simply try not to consider 1 in our sequence sum which will be (odd-1)==even so the maximum length will be N-1 if sum(lst) is odd else the maximum length will be N.

1 Like

Okay, got it! Thanks for this. I think I didn’t understand the problem properly.