Help me in solving EVENSUMSUB problem

My issue

for t in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
b=sum(a)
for i in range(n,-1,-1):
if b%2==0:
print(i)
break
else:
b=b-a[i-1]

My code

for t in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    b=sum(a)
    for i in range(n,-1,-1):
        if b%2==0:
            print(i)
            break
        else:
            b=b-a[i-1]
            
    

Problem Link: Even Sum Subarray Practice Coding Problem

@sureendra_07
plzz refer my c++ code for better understanding

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n];
	    int ans=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    for(int i=0;i<n;i++)
	    {
	        int sm=0;
	        for(int j=i;j<n;j++)
	        {
	            sm+=a[j];
	            if(sm%2==0)
	            {
	                ans=max(ans,j-i+1);
	            }
	        }
	    }
	    cout<<ans<<endl;
	}
	return 0;
}