/*
 * Copyright (C) 2014 Pedro Vicente Gómez Sánchez.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.pedrovgs.problem25;

/**
 * Given a String passed as parameter, can you write a method to calculate input word anagrams?
 *
 * An anagram is a type of word play, the result of rearranging the letters of a word or phrase to
 * produce a new word or phrase, using all the original letters exactly once; for example Torchwood
 * can be rearranged into Doctor Who. The original word or phrase is known as the subject of the
 * anagram. Anagrams are often used as a form of mnemonic device as well.
 *
 * @author Pedro Vicente Gómez Sánchez.
 */
public class Anagrams {
}

@@ -645,16 +645,69 @@
 lem25;%0A%0A
+import java.util.LinkedList;%0Aimport java.util.List;%0A%0A
 /**%0A * G
@@ -1241,11 +1241,1256 @@
 agrams %7B
+%0A%0A  /**%0A   * Combination of recursion and one iterative approach to resolve this problem. The complexity of%0A   * this algorithm is O(N) where N is the size of the input. In space terms the complexity order%0A   * is related to the number of permutations equals to O(N!) where N is the number of chars in the%0A   * input string.%0A   */%0A  public List%3CString%3E get(String input) %7B%0A    List%3CString%3E result = null;%0A    if (input == null) %7B%0A      throw new IllegalArgumentException(%22You can't pass a null String as input.%22);%0A    %7D else if (input.isEmpty()) %7B%0A      result = new LinkedList%3CString%3E();%0A    %7D else %7B%0A      result = getAnagramsInner(%22%22, input);%0A    %7D%0A    return result;%0A  %7D%0A%0A  private List%3CString%3E getAnagramsInner(String prefix, String word) %7B%0A    List%3CString%3E anagrams = new LinkedList%3CString%3E();%0A    int n = word.length();%0A    if (n == 0) %7B%0A      anagrams.add(prefix);%0A    %7D else %7B%0A      for (int i = 0; i %3C n; i++) %7B%0A        //Add the old prefix the new letter%0A        String newPrefix = prefix + word.charAt(i);%0A        //Skip the current letter for the next word%0A        String newWord = word.substring(0, i) + word.substring(i + 1, n);%0A        anagrams.addAll(getAnagramsInner(newPrefix, newWord));%0A      %7D%0A    %7D%0A    return anagrams;%0A  %7D
 %0A%7D%0A

Resolve problem 25