-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.cpp
46 lines (35 loc) · 857 Bytes
/
hash.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
#include<bits/stdc++.h>
using namespace std ;
int main (){
int n;
cout <<"Enter the number of elements in the array"<<endl;
cin>>n;
int arr[n];
for (int i =0;i<n;i++){
cin>>arr[i];
}
// precompute
map<int ,int >mpp;
for(int i=0;i<n;i++){
mpp[arr[i]]++;
}
//iterate in the map
int maxf;
for(auto it:mpp){
cout<<it.first <<"-->"<<it.second<<endl;
}for(auto it:mpp)
{
if(it.second>maxf) maxf=it.second;
else if(it.second =maxf) it.second = maxf;
}
cout << maxf;
// int q ;
//cout<<"Enter the number of queries"<<endl;
// cin >>q ;
// while(q--){
// int numbers;
//
// cin>>numbers;
// cout<<mpp[numbers]<< endl;
// }
}