maximum value in map in c 2b 2b

Solutions on MaxInterview for maximum value in map in c 2b 2b by the best coders in the world

showing results for - "maximum value in map in c 2b 2b"
Tomas
17 Feb 2020
1auto x = std::max_element(m.begin(), m.end(),
2    [](const pair<int, int>& p1, const pair<int, int>& p2) {
3        return p1.second < p2.second; });
4
Lola
12 Apr 2017
1#include <bits/stdc++.h>
2using namespace std;
3
4bool compare(const pair<int, int>&a, const pair<int, int>&b)
5{
6   return a.second<b.second;
7}
8
9int main(int argc, char const *argv[])
10{
11   int n, key, maxn;
12   map<int,int> mp;
13
14   cin>>n;
15
16   for (int i=0; i<n; i++)
17   {
18     cin>>key;
19     mp[key]++;
20   }
21
22   maxn = max_element(mp.begin(), mp.end(), compare)->second;
23
24   cout<<maxn<<endl;
25
26   return 0;
27 }
28