![]() |
VOOZH | about |
Given a map in Java, the task is to find out the entry in this map with the highest key. Examples:
Input: Map = {ABC = 10, DEF = 30, XYZ = 20}
Output: XYZ = 20
Input: Map = {1 = 40, 2 = 30, 3 = 60}
Output: 3 = 60
Approach
for (Map.Entry entry : map.entrySet())
{
// Operations
}Below is the implementation of the above approach:
Map: {ABC=10, DEF=30, XYZ=20}
Entry with highest key: XYZ=20Time complexity: O(NlogN) where N is size of map
Auxiliary Space: O(N)