Concept Flow - Longest Common Substring
Start with two strings
Create 2D table of size (len(s1)+1) x (len(s2)+1)
Initialize all cells to 0
For each character in s1 (i)
For each character in s2 (j)
If s1[i-1
Yes
Set table[i
Update max length and end position if needed
Else
No
Set table[i
After filling table, extract substring from s1 using max length and 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. We keep track of the longest match and extract it at the end.
