LeetCode 947 Most Stones Removed with Same Row or Column - Problem Statement

The problem

Stones are placed on a 2D plane. A stone can be removed if it shares a row or column with another stone that hasn't been removed.

Given stones coordinates, return the maximum number of stones you can remove.

With stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]:

  • Remove (0,1): shares row with (0,0).
  • Remove (1,0): shares column with (0,0).
  • Remove (2,1): shares column with (0,1) or row with (2,2).
  • Remove (1,2): shares column with (2,2).
  • Remove (2,2): shares row with (2,1).
  • 55 stones removed. Only (0,0) remains.

Constraints: 11 \le stones.length 1000\le 1000.