Imagine you're playing a strategic stone removal game on an infinite 2D grid! You have n stones placed at various integer coordinates, with at most one stone per position.
The Rule: You can remove a stone if and only if there's at least one other stone that shares the same row OR the same column with it.
Your Goal: Remove as many stones as possible following this rule!
Given an array stones where stones[i] = [x_i, y_i] represents the coordinates of the i-th stone, return the maximum number of stones you can remove.
Key Insight: This isn't just about counting - it's about understanding connected components! Stones that can "reach" each other through shared rows/columns form groups, and from each group, you can remove all but one stone.
Input & Output
Constraints
- 1 โค stones.length โค 1000
- 0 โค xi, yi โค 104
- No two stones are at the same coordinate point
- All coordinates are integers