Help me in solving EVENSUMSUB problem

My issue

this code failed on the following test case
1
4
8745 8393 3835 4874
but this works perfectly on
1
4
5 3 5 4
which is similar to the first test case.
please help me where is the error in the code.
I have tries to use nested loops to check for every sub-array and find the greatest length of even sub-array.

My code

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

int main() {
	int t;
	cin >> t;
	while(t--){
	  int n;
	  cin >> n;
	  int arr[n];
	  
	  for(int i =0 ; i < n ; i++){
	    cin >> arr[i];
	  }
	  int sum =0;
	  int checksum= -1;
	  int index;
	  int addindex;
	  
	  for(int i =0 ; i < n ; i++){
	    for(int j =0 ; j < n - i ; j++){
	      sum += arr[i+j];
	      if(sum % 2 == 0 && sum >= checksum){
	        checksum = sum;
	        index = i+j;
	        addindex = i;
	      }
	    }
	    sum = 0;
	  }
	  if(checksum == -1){
	    cout << 0 << "\n";
	  }
	  else{
	    cout << index + 1 - addindex << "\n";
	  }
	  
	}
	
}

Problem Link: Even Sum Subarray Practice Coding Problem

you can do it in O(N^2) too.
for linear time calculate prefix sums find the largest odd element and the smallest odd element or largest even element and the smallest even element.

#include<bits/stdc++.h>
using namespace std;
define int long long
void solve(){
int n;
cin>>n;
vectorv(n);
for(int i=0;i<n;i++){
cin>>v[i];

}
int maxi = 0;
for(int i=0;i<n;i++){
	int sum = 0;
	int cnt  =0;

	for(int j=i;j<n;j++){
		
		sum+=v[j];
		
		if(sum%2 == 0){
			cnt = j-i+1;
		}
	}
	
	maxi = max(maxi,cnt);

}
cout<<maxi<<endl;

}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t–){
solve();

}

}