Monday, April 4, 2011

Anagram sets from dictionary

Find all the anagram sets from given list of words.

Input:
5
cat
eat
act
tea
ate
output:
Anagram sets are:
eat tea ate
cat act

1 comment:

  1. Another solution would be:

    Using Trie here will be faster and less space consuming. If you know you are using mostly Engilsh letter you can make it even faster by using simple char[26] (for storing the nodes) while building the trie. So in the trie you will not have to build and store the hash.

    ReplyDelete