title: How to find longest common substring using trees?
body: <p>The longest common substring problem according to wiki can be solved using a suffix tree.<br>
  From <a href="http://en.wikipedia.org/wiki/Longest_common_substring_problem" rel="noreferrer">wiki</a>:  </p>
  
  <blockquote>
    <p>The longest common substrings of a set of strings can be found by
    building a generalised suffix tree for the strings, and then finding
    the deepest internal nodes which have leaf nodes from all the strings
    in the subtree below it  </p>
  </blockquote>
  
  <p>I don't get this.<br>
  Example: if I have:<br>
  <code>ABCDE</code> and <code>XABCZ</code><br>
  then the suffix tree is (some branches from <code>XABCZ</code> omitted due to space):<br>
  <img src="https://i.stack.imgur.com/0xXFI.jpg" alt="enter image description here">    </p>
  
  <p>The longest common substring is <code>ABC</code> but it is not I can not see how the description of wiki helps here.<br>
  <code>ABC</code> is not the deepest internal nodes with leaf nodes.<br>
  Any help to understand how this works?</p>