Cluster Near-Duplicate Pin Images from Pairwise Match Edges
Last updated: November 29, 2026
Quick Overview
A visual similarity model emits pairs of Pin images it believes are near-duplicates. Treating matches as transitive, return how many distinct image clusters exist and the size of the largest one.
0
0
0 solved
A visual similarity model emits pairs of Pin images it believes are near-duplicates. Treating matches as transitive, return how many distinct image clusters exist and the size of the largest one.
Pinterest collapses near-duplicate images so the home feed and search results are not flooded with the same photo. The interviewer wants union find with path compression and union by size, and a discussion of when transitivity is dangerous (chaining unrelated images through a bad edge).
What the Interviewer Expects
- Implements find with path compression or halving
- Uses union by size or rank
- Counts components by decrementing on successful unions
- Returns the largest cluster size correctly
- Raises the chaining risk of transitive closure on noisy model edges
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 prevent one bad edge from merging two large unrelated clusters?
- How would you support removing a match edge later?
- How would you run this on billions of edges with a distributed framework?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Images are 0..n-1, matches are undirected pairs, may contain repeats or edges already implied by transitivity.
- Output (cluster_count, largest_size). n = 0 returns (0, 0)....
High-Level Design
Each image starts in its own set. For every match, find both roots; if they differ, attach the smaller tree under the larger and decrement the cluster count. Sizes live on roots. After processing, the...