Medium
Quiz
#609 Find Duplicate File in System
APPROACH
Given a list paths of directory info strings in the format "dir f1.txt(content1) f2.txt(content2)...", find all sets of duplicate files — files with identical content. Each group must contain at least two paths. Return all such groups as a list of path lists; order within and between groups does not matter.
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"]]
1 of 4
1:00
What is the optimal approach for this problem?