Horje
maximum value in map in c++ Code Example
maximum value in map in c++
auto x = std::max_element(m.begin(), m.end(),
    [](const pair<int, int>& p1, const pair<int, int>& p2) {
        return p1.second < p2.second; });
maximum value in map in c++
#include <bits/stdc++.h>
using namespace std;

bool compare(const pair<int, int>&a, const pair<int, int>&b)
{
   return a.second<b.second;
}

int main(int argc, char const *argv[])
{
   int n, key, maxn;
   map<int,int> mp;

   cin>>n;

   for (int i=0; i<n; i++)
   {
     cin>>key;
     mp[key]++;
   }

   maxn = max_element(mp.begin(), mp.end(), compare)->second;

   cout<<maxn<<endl;

   return 0;
 }




Cpp

Related
set size of a vector c++ Code Example set size of a vector c++ Code Example
differentialble programming Code Example differentialble programming Code Example
find max value in array c++ Code Example find max value in array c++ Code Example
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": Code Example error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": Code Example
difference between programming and coding Code Example difference between programming and coding Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7