FastPrepFind Duplicate Files in a Filesystem
Problems/Find Duplicate Files in a Filesystem

Find Duplicate Files in a Filesystem

Harvey logoHarvey● HardFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report asks for finding duplicate files using iterative traversal, handling cycles and symlinks, recovering from unreadable files, and hashing in buffers for large files. We chose a finite snapshot format and a fixed output order. Our version is about 85% the same as the reported question.

Implement find_dups(root) on a filesystem snapshot. Given a starting directory root and a filesystem snapshot entries, traverse reachable entries with iterative breadth-first search and return groups of duplicate regular files.

Each entry is [path, kind, target, content, readable]:

  • kind is D for a directory, F for a regular file, or L for a symbolic link.
  • A symbolic link stores its destination path in target. Other entries use an empty target.
  • A regular file stores its exact byte content in content. Other entries use empty content.
  • readable is 1 or 0. An unreadable entry is skipped.

Directory children are the entries whose normalized parent path is that directory. Process children in lexicographic path order. Resolve symbolic-link chains; skip a broken link or a link cycle. Visit each resolved directory at most once, so directory links cannot make traversal infinite.

Include each resolved regular file at most once. If several reachable paths resolve to the same file, represent it by the lexicographically smallest path. Group different files only when their contents are byte-for-byte equal. A memory-bounded implementation may bucket by byte length, compute SHA-256 with a fixed one-megabyte buffer, and confirm equal-hash candidates byte-for-byte.

Return only groups containing at least two files. Sort paths inside each group lexicographically, then sort groups by their first path.

Function

findDuplicateFiles(root: String, entries: String[][]) → String[][]

Examples

Example 1

root = "/"entries = [["/","D","","","1"],["/a.txt","F","","same","1"],["/b.txt","F","","same","1"],["/c.txt","F","","other","1"]]return = [["/a.txt","/b.txt"]]

The two readable files with content same form one duplicate group. The third file has different content.

Example 2

root = "/r"entries = [["/r","D","","","1"],["/r/a","D","","","1"],["/r/a/one","F","","x","1"],["/r/two","F","","x","1"],["/r/a/back","L","/r","","1"],["/r/alias","L","/r/a/one","","1"]]return = [["/r/a/one","/r/two"]]

The directory link back to /r is bounded by the visited-directory set. The link /r/alias and /r/a/one identify the same file, so that file appears once under the smaller path.

Example 3

root = "/r"entries = [["/r","D","","","1"],["/r/a","F","","same","1"],["/r/b","F","","same","0"]]return = []

The unreadable file is skipped, leaving no content shared by two reachable files.

Constraints

  • 1 <= entries.length <= 2000.
  • Every entry contains exactly five strings.
  • Every path is unique, normalized, absolute, and contains no trailing slash except /.
  • root names a readable directory entry.
  • Every symbolic-link destination is a normalized absolute path.
  • The sum of regular-file content lengths is at most 200000.
  • readable is exactly 0 or 1.

More Harvey interview questions

  • Highlight and Rank Overlapping CitationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Spreadsheet Formula EvaluatorPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Highlight Matching PhrasesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • File System Shell CommandsONSITE INTERVIEW · Seen Nov 2026
  • Retrieve Vectors by Cosine SimilarityONSITE INTERVIEW · Seen Nov 2026
  • In-Memory Vault File SystemONSITE INTERVIEW · Seen Nov 2026
  • Evaluate an Expression MapONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Word LadderGoogle · ONSITE INTERVIEWGoogle interview questions
  • Shortest Word Transformation SequenceReddit · PHONE SCREENReddit interview questions
  • Word LadderGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Word LadderMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Word Ladder IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Find Minimum City HopsAmazon · OA
  • Shortest Path from Encoded Graph EdgesBitGo · OABitGo interview questions
  • Bus RoutesUiPath · PHONE SCREEN
  • Minimum Bus Routes to a DestinationPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions

Harvey interview experiences

  • Harvey Experienced SWE Phone Screen: 1 Experience
  • Harvey MLE Phone Screen and Virtual Onsite: 1 Experience
All Harvey interview questionsSee Harvey hiring insights
Saved
class Solution {
    public String[][] findDuplicateFiles(String root, String[][] entries) {
      // write your code here
    }
}
Checking account…