FastPrepGroup Duplicate Files by Content
Problems/Group Duplicate Files by Content

Group Duplicate Files by Content

Postman logoPostman● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Postman onsite interview. The report asked candidates to find duplicate files by checksums, going through folders recursively. For this practice, the filesystem comes as matching arrays of file paths and file contents, so the result is always the same. Grouping duplicates keeps the idea of checksum and then verify. Our version is about 92% the same as the reported question.

You are given parallel arrays paths and contents, where contents[i] is the complete content of the file at paths[i].

Group files whose contents are exactly equal. Return one string for every group containing at least two files. Within a group, sort paths lexicographically and join them with a comma. Sort the returned group strings lexicographically.

A production filesystem implementation may use a content checksum to find candidates, but it must verify exact content equality before declaring duplicates so checksum collisions cannot merge different files.

Function

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

Examples

Example 1

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

The first two files have exactly equal contents. The third file is unique.

Example 2

paths = ["b","a","d","c"]contents = ["1","2","1","2"]return = ["a,c","b,d"]

Paths are sorted inside each duplicate group, and the group strings are sorted before returning.

Constraints

  • 1 ≤ paths.length = contents.length ≤ 10^5
  • Every path is unique and non-empty.
  • The total length of all paths and contents is at most 10^6.
  • Paths and contents may contain spaces, but paths do not contain commas.

More Postman interview questions

  • Encode and Decode a String StreamONSITE INTERVIEW · Seen May 2024
  • Configuration SystemOA · Seen Sep 2020
  • Large ResponsesOA · Seen Sep 2020
  • Minimum Swaps to Sort an ArrayOA · Seen Aug 2020
  • Validate IP AddressOA · Seen Aug 2020
  • Without WhitespacesOA · Seen Sep 2019
  • Maximum Laptop Rating in a Price RangeOA · Seen Aug 2019

Similar questions at other companies

  • Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
  • Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Find Duplicate Element PairsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Group AnagramsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Group AnagramsMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions
  • Group AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Group AnagramsExpedia · ONSITE INTERVIEWExpedia interview questions
  • Group AnagramsAkuna Capital · ONSITE INTERVIEWAkuna Capital interview questions
  • Group Anagram StringsLondon Stock Exchange · ONSITE INTERVIEWLondon Stock Exchange interview questions
All Postman interview questionsSee Postman hiring insights
Saved
class Solution {
    public String[] groupDuplicateFiles(String[] paths, String[] contents) {
        // write your code here
    }
}
Checking account…