/*
 * 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.problem29;

/**
 * Given two Strings passed as parameter, can you write a method to return true if this words are
 * anagrams?
 *
 * For example:
 *
 * Input: ana,naa Output: true
 * Input: pedro,ana Output: false
 *
 * @author Pedro Vicente Gómez Sánchez.
 */
public class AreAnagrams {

  public boolean check(String word1, String word2) {
    return false;
  }
}

@@ -928,75 +928,1478 @@
 %0A%0A  
-public boole
+/**%0A   * Iterative algorithm to solve this problem. Two words are anagrams just if contains the same%0A   * number of letters. Using this property, we are going to calculate the number of letters per%0A   * word 
 an
+d
  check
-(String word1, String word2) %7B%0A    return false
+ if the sum is the same. We have used an array of int to represent the letters%0A   * counter. The complexity order of this algorithm is O(N) where N is the number of letters in%0A   * the largest word. In space terms, the complexity order of this algorithm is O(M), where M is%0A   * the number of different letters in the alphabet (we assume ascii, 128 different letters),%0A   * because we need an additional data structure to store information related to the letters%0A   * counter.%0A   */%0A  public boolean check(String a, String b) %7B%0A    if (a == null %7C%7C b == null) %7B%0A      throw new IllegalArgumentException(%22You can't use null Strings as input.%22);%0A    %7D%0A    if (a.length() != b.length()) %7B%0A      return false;%0A    %7D%0A    int%5B%5D lettersA = getLettersAsArray(a);%0A    int%5B%5D lettersB = getLettersAsArray(b);%0A%0A    int valuesA = getSumOfArray(lettersA);%0A    int valuesB = getSumOfArray(lettersB);%0A%0A    return valuesA == valuesB;%0A  %7D%0A%0A  private static int getSumOfArray(int%5B%5D array) %7B%0A    int count = 0;%0A    for (int n : array) %7B%0A      count += n;%0A    %7D%0A    return count;%0A  %7D%0A%0A  private static int%5B%5D getLettersAsArray(String word) %7B%0A    int%5B%5D letters = new int%5B128%5D;%0A    for (char c : word.toCharArray()) %7B%0A      letters%5Bc%5D = letters%5Bc%5D + 1;%0A    %7D%0A    return letters
 ;%0A  

Add iterative solution to problem 29