You are given a word. Generate all the anagrams of that word.
Anagrams of a word means all possible permutations of that word.
Example:
The word "ANT" has following anagrams-Hint View Explanation View Code
Loop through the word, take one letter and rearrange other letters.
For the word "ANT", it will be like below -
i=0, letter=A, rearrange "NT"
i=0, letter=A, rearrange "TN"
i=1, letter=N, rearrange "AT"
i=1, letter=N, rearrange "TA"
i=2, letter=T, rearrange "AN"
i=2, letter=T, rearrange "NA"
Lets simplify the problem. The anagram of 1 letter is the letter only.
Anagram of "A" = "A"
For two letter word, we loop through the word. Each time we separate one letter and anagram the rest of the letters.
For three letter word, it will be like below-