title: Algorithm to find how many times a string A needs to be stated such that it contains string B as substring
body: <p>I haven't been able to come up with a bullet proof answer to this question. My solution fails few cases. I would appreciate some insights.</p>
  
  <h2>Question:</h2>
  
  <p>Given two strings A and B, return the number of times A needs to be stated such that it contains string B? </p>
  
  <p>Example #1:</p>
  
  <ul>
  <li>String A : abcd</li>
  <li>String B : cdabcdab </li>
  </ul>
  
  <p>Should return 3 because:</p>
  
  <ul>
  <li>abcdabcdabcd  ( A repeated 3 times)   </li>
  <li>cdabcdab ( B is contained in now)</li>
  </ul>
  
  <p>Example #2: </p>
  
  <ul>
  <li>String A = abcd</li>
  <li>String B = d</li>
  </ul>
  
  <p>should return 1 because B is already a substring of A.</p>
  
  <p>Example #3:</p>
  
  <ul>
  <li>String A = abcd</li>
  <li>String B = cda</li>
  </ul>
  
  <p>Should return 2 because:</p>
  
  <ul>
  <li>abcdabcd</li>
  <li>cda</li>
  </ul>
  
  <p>Example #4:</p>
  
  <ul>
  <li>String A = abcd</li>
  <li>String B = cdb</li>
  </ul>
  
  <p>Should return -1, it doesn't matter how many times we state A, there is no way we can produce B.</p>
  
  <p>Few insights I have noticed:</p>
  
  <ol>
  <li>Order of characters matter</li>
  <li>A must contain at least all the
  characters in B</li>
  <li>Neither A or B needs to be a substring of the
  other. </li>
  <li>There must be an overlap between the end of one string and
  the beginning of the other.</li>
  </ol>