Remove the Most Map Pins That Share a Row or Column
Last updated: November 29, 2026
Quick Overview
On a grid of map tiles, pins sit at distinct integer coordinates. A pin can be removed if another remaining pin shares its row or column. Return the maximum number of pins that can be removed.
0
0
0 solved
On a grid of map tiles, pins sit at distinct integer coordinates. 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 Google onsite question that rewards one clever modeling step. The interviewer checks whether you realize each connected group of pins can be reduced to a single pin, so the answer is pins minus components, and whether you can union rows with columns instead of pins with pins.
What the Interviewer Expects
- Argues that each component can shrink to one pin
- Models rows and columns as union-find nodes
- Keeps row and column keys from colliding
- Counts components correctly
- Avoids the O(n^2) pin pair loop
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
- Return an actual valid removal order.
- What if a pin can only be removed when another pin shares its row (not its column)?
- How does the answer change if coordinates are 3D?
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: list of
(row, col)pins, all distinct. - A removal is legal if, at the moment of removal, another pin shares its row or column.
- Output: the maximum number of removals....
High-Level Design
Connect two pins whenever they share a row or column. Inside a connected component, we can always remove pins in reverse DFS order until one remains, since each removed leaf still touches its parent; ...