Most Map Pins Removable When Pins Share a Row or Column
Last updated: November 29, 2026
Quick Overview
Map pins sit on integer grid coordinates, at most one per point. A pin can be removed if another remaining pin shares its row or column. Return the maximum number of pins that can be removed.
Meta
November 29, 20260
0
0 solved
Map pins sit on integer grid coordinates, at most one per point. A pin can be removed if another remaining pin shares its row or column. Return the maximum number of pins that can be removed.
A Meta onsite question that sounds like a puzzle but reduces cleanly to counting connected components, framed around clustering Marketplace or check-in pins that share a coordinate line. The interviewer checks the key insight (each component can be reduced to one pin) and an efficient union find over rows and columns.
What the Interviewer Expects
- Show each connected component can be shrunk to a single pin
- Conclude the answer is pins minus components
- Union a pin's row with its column instead of comparing all pairs
- Offset column keys so they do not collide with row keys
- State near-linear time
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
- Prove you can always remove all but one pin per component.
- Return an actual removal order, not just the count.
- What if a pin can only be removed when another pin shares its row (not column)?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
pinsas[x, y]pairs, distinct. - Two pins are linked if they share
xor sharey. - Output: max number removable....
High-Level Design
Insight. Within a connected component, take a spanning tree and remove pins leaf first. Every removed leaf still has its parent sharing a line with it, so all but one pin can go. Pins in different...