In “Find the Longest Repeat in a String”1, we encountered the Longest Repeat Problem, which could be solved using a suffix-tree.

The second additional exercise that we will consider is below.

Assignment

Implement the longest_shared_substring method which takes 2 strings.

The function should return a longest substring of the given strings that occurs in both of them.

Example

>>> longest_shared_substring('TTGGGTCCGGACCCGCCGCTGCGCCGCTGCACCCGCTGGACTAT', 'CAGGAGGTCTCTCGGCCGCTGCGCCGCTGCTCGGAGTTAATTG')
'CGCCGCTGC'