Graph Theory37 sections · 1633 units
Open in Course

LeetCode 200 Number of Islands - Problem Statement

LeetCode 200

Problem: Number of Islands. Task: you are given a 2D2D grid of '11's (land) and '00's (water). An island is formed by connecting adjacent lands horizontally or vertically. Count the number of islands. You will iterate through every cell.

When you find a '11' that has not been visited, you have discovered a new island. Run DFS to mark all cells in that island, then continue searching. Each DFS call from the main loop corresponds to exactly one island.