BackmediumStrings

Identify Prolonged String Overlap Solution

Problem Statement

Given two sequences of characters, determine the length of the longest contiguous or non-contiguous substring common to both.

Example 1
Input
string1 = 'abcdefgh', string2 = 'efghijk'
Output
6

Explanation: The longest common subsequence is 'efgh' with a length of 4.

Example 2
Input
string1 = 'mnopqr', string2 = 'abcdmn'
Output
4

Explanation: The longest common subsequence is 'mn' with a length of 2.

Example 3
Input
string1 = 'xyz', string2 = 'abc'
Output
2

Explanation: There are no common characters between the two strings.

Constraints

  • 1 <= string1.length, string2.length <= 1000
  • string1 and string2 consist only of lowercase English letters.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free