title: How to determine the Time and Space complexity of rotate string algorithm
body: <p>Can anybody explain the time and space complexity for the below rotate string code snippet. </p>
  
  <p>The book from which this example is taken says that </p>
  
  <p>Complexity Analysis</p>
  
  <p>Time Complexity: O(N^2), where N is the length of A.</p>
  
  <p>Space Complexity: O(N), the space used building A+A.</p>
  
  <p>But I don't understand it. Can anybody please explain?</p>
  
  <p>Example 1:
  Input: A = 'abcde', B = 'cdeab'
  Output: true</p>
  
  <p>Example 2:
  Input: A = 'abcde', B = 'abced'
  Output: false </p>
  
  <pre><code>public class RotateString {
  public static void main(String[] args) {
      System.out.println(rotateString("abcd","dabc"));
  }
   public static boolean rotateString(String a, String b) {
         return a.length()==b.length() &amp;&amp; (a+a).contains(b);
   }
  </code></pre>
  
  <p>}</p>