Skip to content

Practice Find Duplicate File in System

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#609
LeetCode Problem

Find Duplicate File in System

Problem Statement

Each paths entry begins with a directory path, followed by one or more space-separated file entries of the form filename(content). Group files with identical content and return only groups containing at least two files. Represent each file as directory_path/filename, not as its content or bare name. Both group order and path order may be arbitrary.

Source: Find Duplicate File in System on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
paths = ["root/a 1.txt(abcd) 2.txt(efgh)","root/c 3.txt(abcd)","root/c/d 4.txt(efgh)","root 4.txt(efgh)"]
Output
[["root/a/2.txt","root/c/d/4.txt","root/4.txt"],["root/a/1.txt","root/c/3.txt"]]

# Example 2

Input
paths = ["root/a 1.txt(abcd) 2.txt(efgh)","root/c 3.txt(abcd)","root/c/d 4.txt(efgh)"]
Output
[["root/a/2.txt","root/c/d/4.txt"],["root/a/1.txt","root/c/3.txt"]]

Constraints

1 <= paths.length <= 2 * 10^4
1 <= paths[i].length <= 3000
1 <= sum(paths[i].length) <= 5 * 10^5
paths[i] consist of English letters, digits, '/', '.', '(', ')', and ' '.
You may assume no files or directories share the same name in the same directory.
You may assume each given directory info represents a unique directory. A single blank space separates the directory path and file info.

Related LeetCode Problems

Practice more problems similar to Find Duplicate File in System.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.