Help me get out of this problem…
Here’s my solution :
#include <bits/stdc++.h>
using namespace std;
bool solve(){
int n;
cin>>n;
long long a[n],sum[10]={0};
for(int i=0;i<n;i++){
cin>>a[i];
sum[a[i]]++;
}
//checking no. of occurances of distinct element
for(int i=0;i<9;i++){
for(int j=i+1;j<10;j++)
if(sum[i] == sum[j] && sum[i] != 0)
return 0;
}
//checking whether they have occurred simultaneously
for(int i=0;i<n;i++){
long long iter = sum[a[i]];
if(iter > 1){
if(i+iter < n){
for(int j=i+1;j<i+iter;j++){
if(a[i] != a[j])
return 0;
}
i += iter-1;
}
}
}
return 1;
}
//main code
int main(){
int t;
cin>>t;
while(t--){
if(solve())
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}