Diff Two Filesystem Hash Trees
Problem statement
Two finite filesystems are represented by parallel path and UTF-8 text arrays. Each path is a unique normalized absolute file path; parent directories are implicit.
Return every file path whose presence or content differs between the two filesystems, sorted lexicographically. A path that appears on only one side is changed.
This is the observable diff operation for a filesystem Merkle tree: equal subtree hashes may be skipped, while unequal leaves are reported. Hashes are an optimization and must not change exact content equality.
Function
diffFileSystems(pathsA: String[], contentsA: String[], pathsB: String[], contentsB: String[]) → String[]Examples
Example 1
pathsA = ["/a.txt","/docs/b.txt"]contentsA = ["one","two"]pathsB = ["/a.txt","/docs/b.txt"]contentsB = ["one","changed"]return = ["/docs/b.txt"]Only the nested file changed.
Example 2
pathsA = ["/a","/gone"]contentsA = ["x","old"]pathsB = ["/a","/new"]contentsB = ["x","fresh"]return = ["/gone","/new"]Removed and added paths are both reported in lexical order.
Example 3
pathsA = []contentsA = []pathsB = []contentsB = []return = []Two empty filesystems have no changed files.
Constraints
0 <= pathsA.length == contentsA.length <= 100000and likewise for B.- Paths are unique within each side and contain at most 500 UTF-8 bytes.
- The combined content size is at most
2 * 10^6UTF-8 bytes. - Hash equality may prune work only when exact equality remains collision-safe.