Challenge: Longest Common Substring

Let's write some code to find the longest common substring.

Problem statement

Given two strings, s1 and s2, write a function that finds and returns the length of the longest substring of s2 and s1 (if any exist).

Input

Two strings.

Output

An integer.

Sample input

string1 = "www.educative.io/explore";
string2 = "educative.io/edpresso";

Sample output

14

Coding exercise

Take a close look and design a step-by-step algorithm before jumping to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the hint and solution provided in the code tab. Good Luck!

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.