Trie data structure can be used... In the trie, you can record item count in each node representing frequency of word consisting of characters on the path from root to current node.
The time complexity to setup the trie is O(Ln) (where L is number of characters in the longest item). To find the top k items, we can traversal the trie, which also costs O(n). So it takes O(n) to solve this problem. Regards, KARTHIKEYAN.V.B PSGTECH CBE -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.