-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrequency.cpp
More file actions
40 lines (40 loc) · 912 Bytes
/
frequency.cpp
File metadata and controls
40 lines (40 loc) · 912 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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
for(int i=1;i<=t;i++)
{
int n;
cin>>n;
int a[n];
unordered_map<int, int> mp;
for(int j=0;j<n;j++)
{
cin>>a[j];
mp[a[j]]++;
}
int big=-1, sbig=-1,cbig=10002,csbig=10002;
for(int j=0;j<n;j++)
{
if(mp[a[j]]>=big) //checking for bigest value
{
big=mp[a[j]];
if(a[j]<cbig)
{
cbig=a[j];
}
}
else if(mp[a[j]]>=sbig && mp[a[j]]<big)
{
sbig=mp[a[j]];
if(a[j]<csbig)
{
csbig=a[j];
}
}
}
cout<<min(cbig,csbig)<<endl;
}
}