Problem · Graph
Most Stones Removed with Same Row or Column
Learn this problemProblem statement
There are stones at distinct integer coordinates on a two-dimensional plane. A stone may be removed if another remaining stone shares its row or its column.
Return the maximum number of stones that can be removed.
Function
removeStones(stones: int[][]) → intExamples
Example 1
stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]return = 5All six stones form one connected component, so one must remain.
Example 2
stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]return = 3Four corner stones are connected and the center stone is isolated, so two stones remain.
Constraints
1 <= stones.length <= 10000 <= stones[i][0], stones[i][1] <= 10000- All coordinates are distinct.