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.

Pinterest
Coding & Algorithms
Software Engineer
Pinterest
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

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
union find
connected components
path compression
deduplication
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 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 Problems
Sample 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...


Submit Your Answer
Markdown supported