title: Interview question: Check if one string is a rotation of other string
body: <p>A friend of mine was asked the following question today at interview for the position of software developer:</p>
  
  <p>Given two string <code>s1</code> and <code>s2</code> how will you check if <code>s1</code> is a <strong>rotated</strong> version of <code>s2</code> ?</p>
  
  <p><strong><em>Example:</em></strong> </p>
  
  <p>If <code>s1 = "stackoverflow"</code> then the following are some of its rotated versions:</p>
  
  <pre><code>"tackoverflows"
  "ackoverflowst"
  "overflowstack"
  </code></pre>
  
  <p>where as <code>"stackoverflwo"</code> is <strong><em>not</em></strong> a rotated version.</p>
  
  <p>The answer he gave was:<br></p>
  
  <blockquote>
    <p>Take <code>s2</code> and find the longest prefix that is a sub string of <code>s1</code>, that will give you the point of rotation. Once you find that point, break <code>s2</code> at that point to get <code>s2a</code> and <code>s2b</code>, then just check if <code>concatenate(s2a,s2b) == s1</code></p>
  </blockquote>
  
  <p>It looks like a good solution to me and my friend. But the interviewer thought otherwise. He asked for a simpler solution. Please help me by telling how would you do this in <code>Java/C/C++</code> ?</p>
  
  <p>Thanks in advance.</p>