https://www.codechef.com/problems/CHEFRECPhttps://www.codechef.com/problems/CHEFRECP This is the link of the problem. I've been covering up all possible test cases in my opinion but still I am getting a wrong answer.
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;cin>>t;
while(t--){
int N;
cin>>N;
map<int,int> recipe;//Map to keep track of the ingredients with its frequency
vector<int> v;//The input array stored here
int lastRecipe;
int temp;
for(int i = 0;i < N;i++){
cin>>temp;
v.push_back(temp);
recipe[temp]++;
}
string ans = "YES\n";
lastRecipe = v[0];
set<int> s;
//check whether the ingredients are contiguous or not
for(int i = 1;i < (int)v.size();++i){
if(v[i]==lastRecipe)s.insert(v[i]);
else{
if(s.find(v[i])!=s.end()){
ans = "NO\n";
break;
}
lastRecipe = v[i];
}
}
if(ans=="NO\n"){
cout<<ans;continue;
}
else{
set<int> tt;
//Check for uniqueness of the frequency
for(auto itr:recipe){
// cout<<itr.first<<" "<<itr.second<<endl;
if(tt.find(itr.second)==tt.end())
tt.insert(itr.second);
else{
ans = "NO\n";break;
}
}
cout<<ans;
}
}
return 0;
}