Group Duplicate Listings That Share Photos or Phone Numbers
Last updated: November 29, 2026
Quick Overview
Each listing has a set of contact phone numbers and perceptual photo hashes. Two listings are duplicates if they share any phone or any photo hash, and duplication is transitive. Return all duplicate groups with at least two listings.
Airbnb
November 29, 20260
0
0 solved
Each listing has a set of contact phone numbers and perceptual photo hashes. Two listings are duplicates if they share any phone or any photo hash, and duplication is transitive. Return all duplicate groups with at least two listings.
Trust and safety at Airbnb hunts for scam networks and copied listings that reuse photos across accounts. This onsite question checks whether you see the transitive linking as connected components and pick union-find with an index from attribute to first owner rather than comparing all pairs.
What the Interviewer Expects
- Avoid the O(n^2) pairwise comparison
- Map each attribute value to the first listing that had it
- Use union-find with path compression and union by size
- Namespace attribute types so a phone and hash with equal strings do not collide
- Return deterministic, sorted output
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
- How would you run this over 10 million listings in a batch job?
- How would you avoid one shared call-center number merging thousands of unrelated listings?
- How would you support incremental updates when a listing adds a new photo?
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: listings with id, phones, photo_hashes. Output: list of groups, each a sorted list of ids, groups sorted. Singletons are omitted. Linking is transitive: L1 shares a photo with L2, L2 shares a p...
High-Level Design
Treat listings as nodes. Instead of building every edge, keep a dict from attribute key to the first listing index that had it. When a later listing has the same key, union the two. This creates at mo...