title: Finding the longest border of a string
body: <p>First, let me tell you what the <a href="https://en.wikipedia.org/wiki/Substring#Border" rel="noreferrer">border of a string</a> is,</p>
  
  <pre><code>let x = "abacab"
  let y = "ababab"
  </code></pre>
  
  <p>The border of a string is a substring which is both a proper prefix and proper suffix of the string — "proper" meaning that the whole string does not count as a substring. The longest border of <code>x</code> is "ab". The longest border of <code>y</code> is "abab" (the prefix and suffix can overlap).</p>
  
  <p>Another example:<br>
  In string "<strong>abcde</strong> hgrab <strong>abcde</strong>", then "abcde" is a prefix as well as suffix. Thus it is also the longest border of the string above.</p>
  
  <p>How can I find the longest border of a string?</p>