A code review tool compares two versions of a file, given as arrays of lines: oldLines and newLines. Lines that appear in both versions in the same relative order are shown as unchanged; everything else is shown as removed or added.
Write unchangedLines(oldLines, newLines) that returns the largest possible number of unchanged lines: the length of the longest common subsequence of the two arrays. Lines match only if they are exactly equal strings.
Input: oldLines = ["<div>","<h1>","<p>","</div>"], newLines = ["<div>","<p>","<span>","</div>"] Output: 3
<div>, <p>, and </div> appear in both, in the same order.
Input: oldLines = ["x = 1"], newLines = ["y = 2"] Output: 0
The only lines differ.
0 <= oldLines.length, newLines.length <= 1000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #530 Unchanged Lines Between Two Versions. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.