Grokking Graph Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Solution: Most Stones Removed with Same Row or Column
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

You have a 2D grid where you place n stones at specific integer coordinates, and each coordinate can have at most 1 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] = [x<sub>i</sub>, yi<sub>i</sub>] is the location of the i<sup>th</sup> stone, return the maximum number of stones that can be removed.

Examples

Example 1:

  • Input: stones = [[1, 1], [2, 2], [3, 1], [3, 2], [4, 4]]
  • Expected Output: 3

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible