Most Stones Removed with Same Row or Column
Explore the process of solving the maximum stones removed problem by applying the Union Find algorithm. Understand how to identify stones sharing rows or columns, and learn to implement an efficient solution in Go. This lesson helps you grasp key algorithmic concepts to handle similar challenges confidently in coding interviews.
We'll cover the following...
Statement
Given an array of stones in a two-dimensional plane, where each stone is represented by a pair of x and y coordinates, find the maximum number of stones we can remove with the following condition:
A stone can be removed if it shares either the same row or the same column with another stone that has not been removed so far.
Stones are provided as an array, stones, of length , where represents the stone. Return the maximum possible number of stones that can be removed.
Constraints:
-
stones.length
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Most Stones Removed with Same Row or Column
What is the maximum number of stones we can remove for the following input?
stones = [[0, 1],[1, 0],[1, 1],[2, 0]]
0
3
4
1
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in main.go in the following coding playground. The supporting code template provided in union_find.go is meant to assist in developing your solution to the problem.
/*⬅️ We have provided a union_find.go file under the "Files" tabof this widget. You can use this file to build your solution.*/package mainfunc removeStones(stones [][]int) int {// Replace this placeholder return statement with your codereturn -1}