Find Duplicate File Groups
Problem statement
A filesystem traversal has produced two equal-length arrays. Entry i contains the unique absolute path of one regular file and that file's complete content.
Two files are duplicates exactly when their complete contents are equal. Return every group containing at least two duplicate paths. Sort paths inside a group lexicographically, then sort groups by their first path. Every path contains printable ASCII characters, so lexicographic order compares their ASCII character values from left to right. Return an empty array when no duplicate group exists.
Examples
Example 1
paths = ["/a/x.txt","/b/y.txt","/c/z.txt","/d/w.txt"]contents = ["red","blue","red","blue"]return = [["/a/x.txt","/c/z.txt"],["/b/y.txt","/d/w.txt"]]The two red files form the first group, and the two blue files form the second. Group order follows each group's first sorted path.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.