Given a list of directory paths and file contents, find all the groups of duplicate files.
Whether you reach for a hash map keyed on content, and whether you think about what this costs on real files.
CodingStandard
Who reports being asked this
Anthropic · Dropbox
What a strong answer does
The core idea is to group by identity of file contents. In the interview version, contents are already given as strings, so the natural data structure is a hash map whose key is the content and whose value is a list of full paths that have that content. After processing all entries, return only the map values whose list length is greater than one. That is the whole algorithmic shape: duplicate detection becomes grouping, and grouping is exactly what a hash table is good at when you can compute a stable key.