FastPrepFind Duplicate Image Files

Find Duplicate Image Files

Abnormal Security logoAbnormal Security● MediumFULLTIMEPHONE SCREEN
Learn

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.

An implementation may use content hashes to reduce comparison work, but exact content equality remains authoritative.

Function

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

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.

Example 2

paths = ["/a","/b","/c"]contents = ["one","two","three"]return = []

Every content value is unique, so there is no duplicate group.

Example 3

paths = ["/zero-b","/zero-a","/filled"]contents = ["","","x"]return = [["/zero-a","/zero-b"]]

Empty files are valid and equal. Their paths are sorted inside the returned group.

Constraints

  • 0 <= paths.length <= 5000.
  • paths.length == contents.length.
  • Paths are unique absolute paths with length from 1 to 100 and contain only printable ASCII characters (code points 32 through 126).
  • File content may be empty.
  • The combined number of characters across all paths and contents is at most 500000.

More Abnormal Security problems

See Abnormal Security hiring insights
public String[][] findDuplicateFileGroups(String[] paths, String[] contents) {
    // Write your solution here.
}
paths["/a/x.txt","/b/y.txt","/c/z.txt","/d/w.txt"]
contents["red","blue","red","blue"]
expected[["/a/x.txt", "/c/z.txt"], ["/b/y.txt", "/d/w.txt"]]
Checking account…