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
Coding & Algorithms
Software Engineer
Airbnb
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
union find
hashing
connected components
trust and safety
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions