The exact full text of that Adobe/LeetCode problem (including all examples and constraints) is copyrighted, so I can’t legally reproduce it verbatim, but I can reconstruct its content accurately in my own words and cover all the elements you need.[3][8]
You are given a list of stones on an infinite 2D grid.[8][3] Each stone is at an integer coordinate $$[x_i, y_i]$$, and there is at most one stone at any coordinate.[8]
A move consists of removing a single stone, with the restriction that the stone you remove must share either:
with at least one other stone that is still on the grid at that moment.[3][8]
You may perform any number of such moves, possibly zero.[3] Your task is to determine the maximum number of stones you can remove.[8][3]
stones, a list/array of n pairs, where each pair stones[i] = [xi, yi].[3][8]The standard observation used in solutions is that stones that are connected through shared rows or columns form connected components in a graph, and from each connected component of size $$k$$, you can remove $$k - 1$$ stones.[5][7][3]
Typical constraints for this problem (LeetCode 947) are:[7][3][8]
These constraints are chosen so that $$O(n^2)$$ adjacency checks are borderline but acceptable, while Union-Find or graph-based DFS/DFS-of-components solutions run comfortably within limits.[5][7][3]
Input:
stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]][3]
One valid sequence of removals is:[5][3]
[0,1] (same row as [0,0]).[1,0] (same column as [0,0]).[1,2] (same column as [2,2]).[2,1] (same row as [2,2]).[0,0] or [2,2] last from its component, as long as another stone in that component still exists when you remove it.The maximum number of stones that can be removed here is 5.[5][3]
Intuition: all 6 stones belong to a single connected component, so you can remove $$6 - 1 = 5$$ stones.[5][3]
Output:
5[5][3]
Input:
stones = [[0,0],[0,2],[1,1],[2,0],[2,2]][3]
Explanation:[3]
Output:
4[3]
Input:
stones = [[0,0]][3]
Explanation:[3]
0.[3]Output:
0[3]
Two main solution families used in interviews:
If you want, I can next reconstruct a full Union-Find or DFS solution and walk through its time/space complexity and implementation details.