Lengthofsub array---not getting right output

#include
#include<unordered_map>
using namespace std ;

int longsubarray(int *a,int n){
int pre = 0 ;
int len = 0 ;
unordered_map<int,int> s ;

for(int i =0 ; i<n;i++){
	pre+= a[i] ;
	if(a[i] == 0 and len == 0) {
		len = 1 ;
	}
	if(pre == 0){
		len = max(len,i+1) ;
	}
	if(s.find(pre) != s.end()){
		len = max(len,i - s[pre]) ;
	}
	else{
		s[pre] = i ;
	}
	
	
}
return len ;

}

int main(int argc, char const *argv[])
{
int n ;
cin >> n ;
int a[n] ;
for(int i = 0 ;i <n;i++){
cin >> a[i] ;
}
int l = longsubarray(a,n) ;
cout << l ;
return 0;
}

hello @guptarahul3100
your code looks correct.
pls save ur code here -> https://ide.codingblocks.com/
and share the link with me.
also mention the input for which it is giving wrong answer