Longest Common Substring
Problem Statement
Input: S1 = "ABCDGH", S2 = "ACDGHR", n = 6, m = 6
Output: 4
Explanation: The longest common substring
is "CDGH" which has length 4.Input: S1 = "ABC", S2 "ACB", n = 3, m = 3
Output: 1
Explanation: The longest common substrings
are "A", "B", "C" all having length 1.Intuition
Approach:
We cannot memoize this, as this will boil down to LCS problem, Because if no
match we will have to return and cannot match earlier elements
So, We check for every character matching using bootom up and update the count
Links
Video Links
Approach 1:
Approach 2:
Approach 3:
Approach 4:
Similar Problems
Last updated