Number of Islands II

Problem

Concept

This is a classic problem which uses disjoint set. In this problem, we will explore adjacent nodes when trying to convert sea to land. But we might run into a case where we do not know to which island group the current island belongs to.

What the question is looking for is number islands which are not overlapping each other.

Code

The time and space complexity for this algorithm is O(m*n)

Last updated