Find Duplicate Photos From Directory Listing Strings
Last updated: November 29, 2026
Quick Overview
Given directory listing strings like 'root/a 1.jpg(abcd) 2.jpg(efgh)', where each file is followed by its content hash in parentheses, return groups of full file paths that have identical content, including only groups with at least two files.
Meta
November 29, 20260
0
0 solved
Given directory listing strings like 'root/a 1.jpg(abcd) 2.jpg(efgh)', where each file is followed by its content hash in parentheses, return groups of full file paths that have identical content, including only groups with at least two files.
Facebook and Instagram store enormous photo volumes, and deduplicating by content hash is a real storage saving. This question tests parsing a compact format and grouping with a hash map, then opens a discussion about doing it for real at scale.
What the Interviewer Expects
- Parse each listing into directory and file tokens
- Split each file token at '(' to get name and content
- Group full paths by content in a hash map
- Return only groups with two or more files
- Discuss hashing, size prefilters, and byte comparison at scale
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- If you only had file paths, how would you find duplicates efficiently?
- Why compare file sizes first?
- How would you handle hash collisions?
- How would you run this over petabytes with a distributed job?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Each string: a directory, then one or more
name(content)tokens separated by single spaces. - Full path is
directory + '/' + name. - Output: list of groups (any order) with two or more paths tha...
High-Level Design
For each listing, split on spaces. The first token is the directory. For every other token, find the (: the name is before it and the content is between it and the trailing ). Append the full path...