I have a need to sort a Map(Key=Word,Value=CountofWord) in the descending order of the count of occurrences and print top 10 words in the Map. What can be the best possible method to do that?
My idea is to build a Multimap(Key=CountofWord,Values=Words) and then print the top 10 elements of the Multimap. But this would take O(n) extra space.
Can there be any other optimized solution?