Your question is Longest Common Substring Solution. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
The City of Englewood Colorado may compare contiguous text segments from two records, such as matching portions of service descriptions. Given two strings, find their longest common substring, where matching characters must occur consecutively in both strings.
Return the substring itself. If multiple longest common substrings have the same length, return the one whose occurrence ends earliest in s1; if still tied, choose the one whose occurrence ends earliest in s2.
Implement longest_common_substring(s1, s2), where s1 and s2 are strings. Return a string containing the longest contiguous sequence appearing in both inputs. Return "" when either input is empty or no characters match.
Use dynamic programming with rolling rows so the solution does not require a full two-dimensional table.
def longest_common_substring(s1, s2):