Trains the technique from
LeetCode 947Most Stones Removed with Same Row or ColumnThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A large pegboard has pins pushed into some of its holes. pins[i] = [row_i, col_i] gives the hole holding pin i, and no two pins share a hole.
Pins come out one at a time. A pin may be pulled only if, at that moment, another pin still in the board sits in the same row or in the same column as it.
Return the largest number of pins that can be pulled out.
Example 1
Pull [0, 2] (its row mate [0, 0] is still in), then [2, 2] (its column mate [2, 0] is still in), then [2, 0] (its column mate [0, 0] is still in). That leaves [0, 0] and [1, 1], which share neither a row nor a column, so three pins come out.
Example 2
The two pins sit in different rows and different columns, so neither one is ever eligible to be pulled.
Example 3
Pull [1, 1], then [1, 0], then [0, 1]; each had a row or column mate on the board at the time, and [0, 0] stays behind.
Example 4
A lone pin has no row or column mate, so nothing can be pulled.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def remove_stones(pins: list[list[int]]) -> int:public int removeStones(int[][] pins)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.