-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlunchtimeaug22---.cpp
More file actions
54 lines (44 loc) · 864 Bytes
/
Copy pathlunchtimeaug22---.cpp
File metadata and controls
54 lines (44 loc) · 864 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
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
int maxFreq(long long int arr[], int n)
{
sort(arr, arr + n);
int max_count = 1, res = arr[0], curr_count = 1;
for (int i = 1; i < n; i++)
{
if (arr[i] == arr[i - 1])
curr_count++;
else
curr_count = 1;
if (curr_count > max_count)
{
max_count = curr_count;
res = arr[i - 1];
}
}
return max_count;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
long long int arr[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
int j = maxFreq(arr, n);
if (j <= (n + 1) / 2)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}
}