As reported: Cohesity Software Engineer 3 (core team, Bangalore), May 2026, round 1 coding. The discussion covered a DFS solution and a disjoint-set (union-find) solution that counts components, and the complexity of each.
This is LeetCode 947 — Most Stones Removed with Same Row or Column. Our write-up: /most-stones-removed-with-same-row-or-column.
On a 2D plane, n stones are placed at integer coordinates; each coordinate point holds at most one stone. A stone can be removed if it shares either the same row or the same column with another stone that has not been removed.
Given stones where stones[i] = [x_i, y_i], return the largest possible number of stones that can be removed.
Example 1
stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]
Output: 5
All six stones are connected through shared rows and columns; you can remove them one by one until one stone is left.
Example 2
stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]
Output: 3
[1,1] shares no row or column with anyone. The other four form one group, from which three can be removed.
Example 3
stones = [[0,0]]
Output: 0
Constraints: 1 <= stones.length <= 1000, 0 <= x_i, y_i <= 10^4, no two stones share a point.
Code runner format: one JSON value per line: stones. Implement removeStones(stones) returning an integer.