Skip to the code
cf.
+25 XP

#713 Count Changed Lines

medium

A code review page shows a badge like +3 -2 for each file. It counts lines as a diff tool would: it keeps as many lines unchanged as possible, in order, and every other line is a deletion from the old version or an insertion in the new one.

Write changedLines(oldLines, newLines) that returns the total number of deleted plus inserted lines in such a smallest diff.

Example 1

Input: oldLines = ["title","intro","body"], newLines = ["title","body","footer"]
Output: 2

Keep title and body; delete intro and insert footer.

Example 2

Input: oldLines = ["a","b"], newLines = ["a","b"]
Output: 0

Nothing changed.

Constraints

  • 0 <= oldLines.length, newLines.length <= 1000
  • Lines are strings and are compared exactly.
Saved in this browser

Run 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).