
Let 'N' = 4, 'K' = 2. The cities are:
Delhi 30
Mumbai 35
Chennai 32
Kolkata 28
The cities sorted by temperature descending are: Mumbai (35), Chennai (32), Delhi (30), Kolkata (28).
The top 2 cities are Mumbai and Chennai.
Therefore, the answer is Mumbai Chennai.
The first line contains two integers, 'N' and 'K'.
The following 'N' lines each contain a string representing the city name and an integer representing its temperature, separated by a space.
Return a list of strings representing the names of the top 'K' cities with the highest temperatures, sorted in descending order of temperature. If two cities have the same temperature, their relative order in the output doesn't matter.
You don’t need to print anything. Just implement the given function.
1 <= 'N' <= 10^5
1 <= 'K' <= 'N'
-100 <= temperature <= 100
City names consist of lowercase and uppercase English letters.
Time Limit: 1 sec
Approach:
Algorithm: