Search⌘ K
AI Features

DIY: Number of Islands

Explore how to identify and count islands—connected land masses—in a 2D grid using effective algorithmic techniques. This lesson helps you solve a typical coding interview problem by implementing a function that processes a matrix of land and water, enhancing your problem-solving skills and understanding of depth-first or breadth-first search methods.

Problem statement

Given an m x n 2D grid map of 1's (land) and 0's (water), return the number of islands.

An island is surrounded by water and is ...