Help me in solving EVENSUMSUB problem

My issue

t = int(input())
for _ in range(t):
a = int(input())
l = list(map(int, input().split()))
s1 = sum(l)

if a == 1:
    if s1 % 2 == 0:
        print(1)
    else:
        print(0)
    continue

while s1 % 2 != 0:
    s1 -= l.pop()

print(len(l))

My code

t = int(input())
for _ in range(t):
    a = int(input())
    l = list(map(int, input().split()))
    s1 = sum(l)
    
    if a == 1:
        if s1 % 2 == 0:
            print(1)
        else:
            print(0)
        continue
    
    while s1 % 2 != 0:
        s1 -= l.pop()
    
    print(len(l))

Problem Link: Even Sum Subarray Practice Coding Problem

@krishna3363
plzz refer my c++ code for better understanding of the logic

#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;
}