My code is failing on an hidden test case but i am not able to understand

#include<bits/stdc++.h>
using namespace std;
void subArraySum(vector<int> arr,int N,int& maxLength,int& maxSum,int& sum){
    for(int i=0;i<N;i++){
        sum=0;
        for(int j=i;j<N;j++){
            sum+=arr[j];
            if((sum)>=maxSum && sum%2==0){
                maxSum=sum;
                maxLength=j-i+1;
            }

        }
    }

}
int main(){
    int T;
    cin>>T;
    while(T--){
        bool hasEven=false;
        int sum=0;
    int N;
    int maxSum=0;
    int maxLength=0;
    cin>>N;
    vector <int> arr;
    for(int i=0;i<N;i++){
        int temp;
        cin>>temp;
        arr.push_back(temp);
        sum+=arr[i];
        if(arr[i]%2==0){
            hasEven=true;
        }
    }
        if(sum%2==0){
        cout<<N<<endl;
        continue;
    }
    if(!hasEven){
        cout<<"0"<<endl;
        continue;
    }

    subArraySum(arr,N,maxLength,maxSum,sum);
    cout<<maxLength<<endl;
    
    }

}

@achiever_cpp
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;
}