Every "compare" view you've used — git diff, Google Docs suggestions, code review — rests on one algorithm: the Longest Common Subsequence. Here's a diff checker that computes a real LCS diff in the browser, live as you type.
🔀 Try it (edit either side): https://dev48v.infy.uk/solve/day13-diff-checker.html
The naive way is wrong
Comparing line 1 to line 1, line 2 to line 2… breaks the moment someone inserts a line near the top — everything after looks "changed." You need to find what the two texts have in common, in order.
LCS: the longest shared subsequence
Treat each text as a list of lines. The LCS is the longest sequence of lines present in BOTH, in the same order. Everything in the LCS is "unchanged"; lines only in the original are deletions, lines only in the new version are additions.
Compute it with a DP table
Build a grid of LCS lengths, fill it bottom-up, then backtrack from the corner to label each line keep / add / remove. That's the whole engine in ~30 lines. (git uses Myers' algorithm, an optimized cousin of the same idea.)
🔨 Full build (split → DP table → backtrack → render) on the page: https://dev48v.infy.uk/solve/day13-diff-checker.html
Part of SolveFromZero. 🌐 https://dev48v.infy.uk












