Directory Snapshot Diff

Asked at Meta· Onsite

Reported by the problem's creator, not verified

Import another question

A tool compares two snapshots of a directory. A snapshot is a list of [path, digest] pairs, one per file, where digest is a string that changes when the file's contents change. Paths are unique within a snapshot and the list is in no particular order.

Implement diff_snapshots(before, after), which returns the report lines for turning before into after. Each test gives two snapshots and checks the exact list of lines.

Examples

  1. Example 1

    Input: before = [["a.txt","h1"],["b.txt","h2"],["src/c.py","h3"]], after = [["a.txt","h1"],["b.txt","h9"],["src/d.py","h4"]]

    Output: ["+ src/d.py","- src/c.py","~ b.txt"]

    Explanation: src/d.py appears only in after, so it is added. src/c.py appears only in before, so it is deleted. b.txt is in both with a different digest, so it is modified. a.txt is unchanged and is not listed.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.