Remove stones sharing a row or column
Stones lie on a grid at the distinct points [x, y] of stones. One move removes a stone that shares its row or its column (the same x or the same y) with at least one other stone still on the grid. Return the largest number of stones you can remove, making the moves in the best order.
There is at least one stone, and coordinates are integers from 0 to 10⁴. Aim for near-linear time, not a comparison of every pair of stones.
Besides the tests, one large input (3,000 stones) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
max_removed([[0,0],[0,3],[2,3],[5,5],[5,1]])→3max_removed([[1,1]])→0max_removed([[0,0],[1,1],[2,2]])→0