Merge Duplicate Business Listings Sharing Any Contact Field

Last updated: November 29, 2026

Quick Overview

Each listing has an id and a set of normalized contact fields (phone, website domain, address hash). Two listings belong to the same real business if they share any field directly or through a chain of other listings; return the resulting groups.

Yelp
Coding & Algorithms
Software Engineer
Yelp
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Each listing has an id and a set of normalized contact fields (phone, website domain, address hash). Two listings belong to the same real business if they share any field directly or through a chain of other listings; return the resulting groups.

Duplicate listings split reviews and photos across pages, which hurts both consumers and business owners who pay for Yelp Ads. This is a connected components problem, and the interviewer wants to see union find (or BFS) with a field to owner index so you avoid comparing every pair of listings.

What the Interviewer Expects
  • Recognize transitive matching as connected components
  • Avoid O(n^2) pairwise comparison by indexing field to first owner
  • Implement union find with path compression and union by size
  • Normalize fields before matching and namespace them by type
  • Discuss false merges and why some fields should be weaker evidence
Key Topics to Cover
union find
connected components
hashing
entity resolution
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
  • A chain store shares one website across 400 locations. How do you avoid merging them all?
  • How would you run this incrementally as new listings arrive?
  • How would you un-merge if a moderator flags a bad merge?
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: list of (listing_id, fields) where each field is a string like phone:4155550100 or web:joes.com. Prefixing with the type prevents a phone and a zip code that happen to share digits from m...

High-Level Design

Treat listings as nodes; a shared field is an edge. Instead of building all edges, keep a dictionary from normalized field to the first listing that had it. When a later listing has the same field, un...


Submit Your Answer
Markdown supported

Related Questions