Implement a simple version of diff. Given two lists of lines, produce an edit script based on their longest common subsequence:
diff_lines(a, b): a list of strings, one per line: " line" for unchanged lines, "- line" for removed lines and "+ line" for added lines. When there's a choice, output removals before additions at each change point.apply_diff(a, script): rebuild b from a and the script, checking that unchanged and removed lines match a (raise ValueError otherwise).diff_stats(script): {"added": n, "removed": n, "unchanged": n}.Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.
Start 7-day free trial