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.