Longest Common Substring

Find the longest contiguous substring that appears in both strings using an iterative approach.

Code

Algorithms
longest = ''
for i in range(len(a)):
    for j in range(i + 1, len(a) + 1):
        current = a[i:j]
        if current in b and len(current) > len(longest):
            longest = current
return longest

Parameters

First string

Second string

Server

More Python Snippets