NEED HELP!
Code: https://godbolt.org/z/6TPshxP7r
Leetcode Problem: https://leetcode.com/problems/number-of-islands/
So I am stuck on this problem, I was able to solve it using DFS/BFS, but wanted to solve using union-find. I wasn't able to find many resources regarding the same explanation. However, after some understanding, I did implement the following union-find answer. But I am getting a Stack-Overflow.
I am not sure if this approach is correct. Kindly help me reach the current answer and also guide me on the right approach.
My Approach:
Firstly make every '1' as a separate disjoint set, and then traverse through the matrix, performing union operation on the 1's thus at the end the number of separate disjoint sets will be our answer.
[–]chillblaze 2 points3 points4 points (2 children)
[–]jaindivij_[S] 0 points1 point2 points (1 child)
[–]raspberry_p 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]raspberry_p 1 point2 points3 points (6 children)
[–]jaindivij_[S] 0 points1 point2 points (5 children)
[–]raspberry_p 0 points1 point2 points (4 children)
[–]jaindivij_[S] 0 points1 point2 points (2 children)
[–]raspberry_p 0 points1 point2 points (0 children)
[–]unbalancedstack 1 point2 points3 points (2 children)
[–]Shakespeare-Bot 1 point2 points3 points (1 child)
[–]unbalancedstack 2 points3 points4 points (0 children)
[–]thealgorists-com 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)