Phase 1: What do they have in common?

You have seen substring matching before: find a contiguous run of characters that appears in both strings. Simple enough. But what if the shared characters do not have to sit next to each other? What if they only need to appear in the same ORDER, with arbitrary gaps between them?

That is the difference between a common substring and a common subsequence. A substring is a window you slide across both strings. A subsequence is a scattered trail of breadcrumbs that preserves order but tolerates gaps. The longest common subsequence (LCS) asks: what is the longest trail you can find?

text1
text2

Find the longest string that appears in BOTH, reading each left to right. Order must be preserved — but chars can be NON-ADJACENT in each source. That last constraint is why this isn't just a substring search.

What's the longest run of characters you can find that lives in both?