Skip to content

Practice Most Stones Removed with Same Row or Column

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#947
LeetCode Problem

Most Stones Removed with Same Row or Column

Problem Statement

On a 2D plane, we place n stones at some integer coordinate points. Each coordinate point may have at most one stone. A stone can be removed if it shares either the same row or the same column as another stone that has not been removed. Given an array stones of length n where stones[i] = [xi, yi] represents the location of the ith stone, return the largest possible number of stones that can be removed.

Source: Most Stones Removed with Same Row or Column on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]
Output
5

# Example 2

Input
stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]
Output
3

# Example 3

Input
stones = [[0,0]]
Output
0

Constraints

1 <= stones.length <= 1000
0 <= xi, yi <= 10^4
No two stones are at the same coordinate point.

Related LeetCode Problems

Practice more problems similar to Most Stones Removed with Same Row or Column.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.