Answers for "find max element in map c++"

C++
1

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; });
Posted by: Guest on September-16-2021
1

find max value in map

public class NewClass4 {
  public static void main(String[] args)
  {
    HashMap<Integer,Integer>map=new HashMap<Integer, Integer>();
    map.put(1, 50);
    map.put(2, 60);
    map.put(3, 30);
    map.put(4, 60);
    map.put(5, 60);
    int maxValueInMap=(Collections.max(map.values()));  // This will return max value in the Hashmap
    for (Entry<Integer, Integer> entry : map.entrySet()) {  // Itrate through hashmap
      if (entry.getValue()==maxValueInMap) {
        System.out.println(entry.getKey());     // Print the key with max value
      }
    }

  }
}
Posted by: Guest on March-16-2021
4

max element in array c++ stl

*max_element (first_index, last_index);
ex:- for an array arr of size n
*max_element(arr, arr + n);
Posted by: Guest on May-21-2020

Browse Popular Code Answers by Language