Help me in solving MISSP problem

My issue

please help me why codechef is bombarding me with wrong answer when my code seems correct gives same sample output and very similar to accepted submissions

My code

#include <iostream>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int a[n];
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        for (int i = 0; i < n; i++) {
            if(a[i]>0){
               for (int j = i+1; j < n; j++) {
                    if (a[i] == a[j]&& i!=j) {
                    a[i] = a[j] = -1;
                    }
               }
            }
        }

        for (int i = 0; i < n; i++) {
            if (a[i] != -1) {
                cout << a[i] << " ";
            }
        }

        cout << endl;
    }
    return 0;
}

Problem Link: MISSP Problem - CodeChef

@prathamsch77
Have corrected your code
one case is missing when a[i] is 0 .

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

bool sol(int n,string s,char c1,char c2){
    
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]&&s[i]==c1)
            s[i]=s[i+1]=c2;
    }
    for(int i=0;i<n-1;i++){
        if(s[i]!=s[i+1])
        return 0;
    }
    return 1;
}
int main(){
	  
	  int t;cin>>t;
	  while(t--){
	      
	      int n;cin>>n;
	      string s;
	      cin>>s;
	      
	      if(sol(n,s,'0','1')||sol(n,s,'1','0'))
	      cout<<"YES"<<endl;
	      else
	      cout<<"NO"<<endl;
	      
	  }
	  return 0;
}