15% off all plans & roadmaps Use code
See plansLeetCode 695 · Solution & editorial
You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
Max Area of Island is a Graph Traversal Patterns (DFS & BFS) problem, in the Graph DFS - Connected Components / Island Counting subpattern. The pattern covers DFS/BFS traversal, topological sort, shortest paths, Union-Find, and MST
Use DFS to find connected components and count islands in grids. Flood fill and province counting problems.
The reference solution runs in O(m * n) time and O(m * n) space.
Max Area of Island has been reported in interviews at Amazon, Bloomberg, DoorDash, eBay, Facebook, Google, LinkedIn, Microsoft.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Max Area of Island is a Graph Traversal Patterns (DFS & BFS) problem, in the Graph DFS - Connected Components / Island Counting subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.