Group Duplicate Photos in an iCloud Library by Content Hash
Last updated: November 29, 2026
Quick Overview
Given a list of photos as (photo_id, byte_size, content_hash) tuples, return every group of photo ids that are true duplicates, where duplicates share both size and hash. Each group should be sorted, and groups should be ordered by their smallest id.
Apple
November 29, 20260
0
0 solved
Given a list of photos as (photo_id, byte_size, content_hash) tuples, return every group of photo ids that are true duplicates, where duplicates share both size and hash. Each group should be sorted, and groups should be ordered by their smallest id.
A warm-up in the style of Apple phone screens for Photos and iCloud teams, where deduplication of a user's library is a real product concern. The interviewer checks that you pick a hash map keyed on the right composite key and produce deterministic output.
What the Interviewer Expects
- Choose a composite key (size, hash) and explain why size alone is insufficient
- Use a dictionary of lists for a single linear pass
- Return only groups with two or more photos
- Make the output order deterministic
- State time and space complexity clearly
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
- Hashing full files is expensive; how would you avoid hashing photos whose size is unique?
- How would you handle the same photo stored in HEIC and JPEG formats?
- How would you run this across 2 TB of photos that do not fit in memory?
- What if two different photos collide on a weak hash?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a list of (photo_id, size, content_hash) tuples, where photo_id is an int. Output: a list of groups, each a sorted list of ids with at least two members, ordered by first id. Two photos are...
High-Level Design
One pass over the photos, bucketing ids into a dictionary keyed by the tuple (size, content_hash). Including size in the key is cheap protection against hash collisions and mirrors how real dedup pi...