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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
union find
connected components
coordinate compression
graph modeling
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
  • 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 Problems
Sample Answer
Requirements
  • Input: pins as [x, y] pairs, distinct.
  • Two pins are linked if they share x or share y.
  • 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...


Submit Your Answer
Markdown supported