Concept Flow - Longest Common Substring
Start with two strings
Create 2D table of size (m+1)x(n+1)
Initialize all cells to 0
For each character in string1 (i)
For each character in string2 (j)
If chars match: table[i
Update max length and end position if needed
Else: table[i
After filling table, extract substring from end position
Return longest common substring
Done
We build a table to track matching characters between two strings. When characters match, we extend the substring length from the previous diagonal cell. We keep track of the longest length and its position to extract the substring at the end.
