-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCHEFRECP.cpp
71 lines (61 loc) · 1.17 KB
/
CHEFRECP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main() {
// t-> number of test cases
int t;
cin>>t;
while(t--)
{
//n-> size of an array
int n;
cin>>n;
//taking input and storing frquency of an elements
vector<int> v(n);
unordered_map<int,int> map;
int curr=0;
bool flag=1;
for(int i=0;i<n;i++)
{
cin>>v[i];
if(curr==v[i])
map[v[i]]++;
else if(map[v[i]]==0)
{
map[v[i]]++;
curr=v[i];
}else
{
flag=0;
}
}
if(!flag)
{
cout<<"NO"<<endl;
continue;
}
//storing the frquency in temp vector
vector<int> temp;
for(auto it:map)
{
temp.push_back(it.second);
}
//sorting an array
sort(temp.begin(),temp.end());
for(int i=0;i<temp.size()-1;i++)
{
if(temp[i]==temp[i+1])
{
flag=0;
break;
}
}
if(!flag)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return 0;
}