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

/**
 * Assume you have a method isSubstring which checks if one word is a substring of another. Given
 * two strings, s1 and s2, write code to check if s2 isa rotation of s1 using only
 * one call to isSubstring (e.g., "waterbottle" is a rotation of "erbotlewat").
 *
 * @author Pedro Vicente Gómez Sánchez.
 */
public class IsRotationUsingIsSubstring {

}

@@ -1000,10 +1000,1128 @@
 ring %7B%0A%0A
+  /**%0A   * Iterative algorithm used to solve this problem. The complexity order of this algorithm in time%0A   * and space terms is O(N) where N is the sum of input strings lengths. To solve this problem we%0A   * check if the length of input strings is the same and for strings with the same length we are%0A   * going to concatenate s1 with s1 check if duplicated s1 contains s2.%0A   *%0A   * s1 = waterbottle%0A   * s2 = erbotlewat%0A   * s1s1 = waterbottlewaterbottle%0A   * return %22waterbottlewaterbottle%22.contains(erbotlewat)%0A   */%0A  public boolean check(String s1, String s2) %7B%0A    validateInput(s1, s2);%0A%0A    if (haveSameLength(s1, s2)) %7B%0A      String s1s1 = s1 + s1;%0A      return isSubstring(s1s1, s2);%0A    %7D%0A    return false;%0A  %7D%0A%0A  private boolean isSubstring(String s1s2, String s2) %7B%0A    return s1s2.contains(s2);%0A  %7D%0A%0A  private void validateInput(String s1, String s2) %7B%0A    if (s1 == null %7C%7C s2 == null) %7B%0A      throw new IllegalArgumentException(%22You can't pass null instances of s1 or s2 as parameter.%22);%0A    %7D%0A  %7D%0A%0A  private boolean haveSameLength(String s1, String s2) %7B%0A    return s1.length() == s2.length();%0A  %7D%0A
 %7D%0A

Add iterative solution to problem 56