Most Stones Removed with Same Row or Column Problem
Most Stones Removed with Same Row or Column Problem — ExecCode Medium DSA Practice
Solve the Most Stones Removed with Same Row or Column problem on ExecCode. Free online medium DSA practice in Hashing. Write and run code in Java, C++, Python — no signup required to run.
Problem description
On a 2D plane, stones sit at integer coordinates. A stone can be removed if it shares a row or a column with another stone that has not yet been removed. Given the positions of all stones, return the maximum number of stones you can remove; equivalently, every connected group of stones (connected through shared rows/columns) can be reduced to exactly one surviving stone.
Examples
Input stones = [[0, 0], [0, 1], [1, 0], [1, 2], [2, 1], [2, 2]]; Output 5. Input stones = [[0, 0], [0, 2], [1, 1], [2, 0], [2, 2]]; Output 3. Input stones = [[0, 0]]; Output 0
Constraints
1 ≤ stones.length ≤ 1000 0 ≤ xi, yi ≤ 10⁴ No two stones share the exact same coordinate.
Practice Most Stones Removed with Same Row or Column free on ExecCode. Browse DSA problems, topic map, and placement guides.