Anagrams in an Array of Strings

You are given an array of strings and you are asked to display all the anagrams within the array. For those who don’t know, two words are anagrams if they contain the same characters.

Comments

  1. Sort every string in the array(can be done fast with radix-sort) then while doing that for each string store in a hash-table the original and the sorted one, when you encounter a string that's already in the hash-table print these pair of anagrams.

    ReplyDelete
  2. oops, didn't notice you will have duplicate prints, so instead of printing the pair you can add the current anagram to the hash-table slot where the sorted version appears. at the end print everything.

    ReplyDelete

Post a Comment

Popular posts from this blog