Find Duplicate Image Files
Updated
Problem statement
You are given two arrays of the same length, paths and contents. They come from walking through the folders of a file system. Entry i describes one regular file: paths[i] is its absolute path and contents[i] is its complete content. No two files share a path.
Two files are duplicates when their complete contents are exactly equal. Find every group of duplicate files that holds at least two paths, and return those groups. If there is no such group, return an empty array.
Sort the paths inside each group in lexicographic order. Every path uses only printable ASCII characters, so this order compares two paths by their ASCII character values from left to right. Then sort the groups by their first path.
You may use hashes of the contents to cut down on comparisons. But the final test is always exact equality of the contents.
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"]]Files /a/x.txt and /c/z.txt both hold red, and /b/y.txt and /d/w.txt both hold blue. The red group comes first because its first path, /a/x.txt, sorts before /b/y.txt.
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"]]Files /zero-b and /zero-a are both empty, so they are duplicates. /filled has no match. Inside the group, /zero-a sorts before /zero-b, so the answer is that one 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 Phone Screen questions
Similar questions at other companies
- Group AnagramsWorkday · PHONE SCREEN
- Group AnagramsEPAM · PHONE SCREENEPAM interview questions
- Find Duplicate File GroupsAnthropic · PHONE SCREENAnthropic interview questions
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Group AnagramsMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
- Stable Top K Frequent WordsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Group AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Shared Courses for Each Pair of StudentsWhatNot · PHONE SCREENWhatNot interview questions
- Credit Card Command ProcessorChime · PHONE SCREEN
- Employee Salary Report by GroupRippling · PHONE SCREENRippling interview questions