Prepin
Log in

Identify duplicate files within a file system.

Approach / Explanation

In this question, the interviewer is requesting that you suggest an algorithm or method for identifying duplicate files in a computer's file system. The first thing to clarify is what defines a 'duplicate' file—this could refer to files that share the same name, have identical sizes, or contain the same content. Be prepared for the interviewer to elaborate on any of these definitions. Here are some points to guide you: Clearly define the criteria you will use to identify duplicate files. Will it be based on the file name, file size, or file content? Choose an appropriate data structure for storing and accessing the file data. Options like hashmaps or sets might be beneficial. Consider the scalability of your solution, as the file system may contain a vast number of files.

Suggested Answer

If we aim to find files with identical content, we should compare them based on their content rather than their names. Therefore, we can utilize a hashmap where the key is the hash value of each file, and the value is the path of the file. This is how I would approach it: Traverse the entire directory of files using Depth-First Search (DFS). For each file, compute a unique hash (for example, using MD5 or SHA256 algorithms). If the hash is not present in the hashmap , insert this hash along with the corresponding file path. If the hash already exists in the hashmap , it indicates that we have found a duplicate file.

Alternative Answer

In the event that the interviewer indicates a scenario in which only files with identical names are treated as duplicates, the previous method can be easily adjusted as follows: Implement a Depth-First Search (DFS) or Breadth-First Search (BFS) to explore the directory. Add each file's name to a hashset . If the filename is already present in the hashset , it is considered a duplicate file.

Question Details

Difficulty & Category

Medium
algorithms

Companies

Dropbox

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.