Iterating through the list to create a map structure I o(n).
Then we sort it in o(nlogn)
After that we can simply pick the top k elements.
Total complexity o(nlogn)
Iterating through the list to create a map structure I o(n).
Then we sort it in o(nlogn)
After that we can simply pick the top k elements.
Total complexity o(nlogn)