Description
Given stones on a 2D plane, remove stones that share row or column with another stone. Return max stones that can be removed.
Examples
Input:
stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]Output:
5Explanation:
All but one can be removed.
Input:
stones = [[0,0],[1,1],[2,2],[3,3]]Output:
0Explanation:
No two stones share the same row or column, so no stones can be removed.
Input:
stones = [[0,1],[1,0],[1,1],[2,1],[2,2]]Output:
4Explanation:
All stones are connected through shared rows or columns, forming one connected component. It is possible to remove 4 stones, leaving 1 stone remaining.
Constraints
- •
1 ≤ stones.length ≤ 1000