Max Area of Island
Problem Statement
You are given a grid of 0s (water) and 1s (land). An island is a group of land cells joined up, down, left or right. The area of an island is how many cells it has. Return the largest area of any island. If the grid has no land, return 0.
grid, an m × n grid of 0s and 1s.
The largest island area, or 0 if there is no land.
The largest island is the group around the middle-right, with 6 cells. Cells that touch only at a corner do not join, so they are not counted.
There is no land, so the largest area is 0.
- • 1 ≤ m, n ≤ 50, where m is the number of rows and n is the number of columns
- • grid[i][j] is 0 or 1
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
From each land cell, run a new search to measure its island; keep the largest size
Scan the grid; each unmarked land cell starts a DFS that returns the size of its island
For every land cell, run a BFS with its own new visited array. It counts the cells it reaches, which is the size of that cell's island. Keep the largest count. Every island is measured once for each of its cells, so the same work is repeated many times.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Graph BFS / DFS translate into production architectures and low-level memory mechanics.