-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistolist.cpp
More file actions
48 lines (42 loc) · 715 Bytes
/
listolist.cpp
File metadata and controls
48 lines (42 loc) · 715 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int mostFrequent(vector < int > & arr, int n)
{
unordered_map < int, int > hash;
int res = -1;
for (int i = 0; i < arr.size(); i++)
{
hash[arr[i]]++;
}
for (auto i: hash)
{
if (res < i.second)
{
res = i.second;
}
}
return res;
}
int main() {
int a = 0;
int b = -1;
int t, n, f;
cin >> t;
while (t--) {
cin >> n;
vector < int > arr(n);
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
f = mostFrequent(arr, n);
if (f == n) {
cout << a << endl;
} else if (f <= 1 && n>=2) {
cout << b << endl;
} else {
cout << (n-f+1) << endl;
}
}
return 0;
}