FastPrepFind Duplicate Files by Content

Find Duplicate Files by Content

Microsoft logoMicrosoft● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

You are given a flattened recursive folder listing as parallel arrays of unique file paths and exact file contents. Return every group of files that have identical content.

Omit singleton groups. Sort paths inside each group lexicographically, then sort groups by their first path.

Function

findDuplicateFiles(paths: String[], contents: String[]) → String[][]

Examples

Example 1

paths = ["/a/x.txt","/b/y.txt","/a/z.txt","/c/w.txt"]contents = ["hello","same","same","hello"]return = [["/a/x.txt","/c/w.txt"],["/a/z.txt","/b/y.txt"]]

Two content values each occur twice; sorting paths and then groups produces the shown order.

Example 2

paths = ["/a","/b"]contents = ["left","right"]return = []

No two files have identical content.

Constraints

  • 0 <= paths.length = contents.length <= 100000
  • 1 <= paths[i].length <= 300
  • 0 <= contents[i].length <= 10000
  • Paths are unique

More Microsoft problems

See Microsoft hiring insights
public String[][] findDuplicateFiles(String[] paths, String[] contents) {
  // Write your code here.
}
paths["/a/x.txt","/b/y.txt","/a/z.txt","/c/w.txt"]
contents["hello","same","same","hello"]
expected[["/a/x.txt", "/c/w.txt"], ["/a/z.txt", "/b/y.txt"]]
Checking account…