Find Duplicate Files by Content
AnthropicSoftware Engineer · OnsiteLast updated
This question evaluates the ability to parse file-system-style input, group files by identical content, and manage deduplication using appropriate data structures and algorithms.
You are given a list of directory descriptions. Each description has the following format:
root_directory file_name_1(content_1) file_name_2(content_2) ...
For example:
/data/a 1.txt(abcd) 2.txt(efgh)
This means the directory /data/a contains file /data/a/1.txt with content abcd and file /data/a/2.txt with content efgh.
Return all groups of file paths whose file contents are identical. Only include groups with at least two files. The order of groups and the order of paths inside each group do not matter.
Example:
Input:
["/data/a 1.txt(abcd) 2.txt(efgh)", "/data/b 3.txt(abcd)", "/data/c 4.txt(efgh) 5.txt(xyz)"]
Output:
[["/data/a/1.txt", "/data/b/3.txt"], ["/data/a/2.txt", "/data/c/4.txt"]]
Constraints:
1 <= number of directory descriptions <= 10^4- The total number of files is at most
10^5. - File names and directory names do not contain spaces.
- File content is represented as a string without parentheses.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.