Cluster Duplicate Google Business Profile Listings With Union-Find in Pandas
Last updated: November 29, 2026
Quick Overview
Given business listings with name, phone and ZIP code, group listings that refer to the same business when they share a normalized phone number or a normalized name within the same ZIP, applying matches transitively.
0
0
0 solved
Given business listings with name, phone and ZIP code, group listings that refer to the same business when they share a normalized phone number or a normalized name within the same ZIP, applying matches transitively.
Duplicate listings are a real data quality problem for Google Business Profile and Maps. This take-home style task checks normalization, and especially whether you see that pairwise matches must be chained: A matches B by phone and B matches C by name, so all three are one cluster, which a simple groupby cannot express.
What the Interviewer Expects
- Normalize phones to digits and the last ten digits
- Normalize names by lowercasing, removing punctuation and legal suffixes
- Generate links from each blocking key without comparing all pairs
- Use union-find (or connected components) for transitive grouping
- Return a stable cluster id such as the smallest listing id
- Discuss false merges and how to guard against them
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- A shared call center phone number links 500 unrelated shops. How do you prevent the giant cluster?
- How would you add fuzzy name matching without O(n^2) comparisons?
- How would you evaluate precision and recall of the clustering?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
listings(listing_id, name, phone, zip). Phones come in many formats or are missing or junk like n/a. Two listings match if their normalized phones are equal, or their normalized names are equal an...
Approach
Normalize first: phone to its last 10 digits (dropping +1 and punctuation), name to lowercase words without apostrophes, punctuation or suffixes like Inc and LLC. Each key acts as a blocking key: all ...