 All Problems
Max Area of Island
medium
graph
depth-first search
breadth-first search
matrix
union find
amazon
google
facebook
microsoft

You are given an m x n binary matrix grid. An island is a group of 1's connected 4-directionally. Return the maximum area of an island in the grid (area = number of cells). If there is no island, return 0.

Example:

Input:
4 5
0 0 1 0 0
0 1 1 1 0
0 1 0 0 0
0 0 0 0 0
Output: 4

Input format: First line: m n. Then m lines of n space-separated integers.

Output format: Maximum island area.

Run to check your code against the sample cases, or submit to run every case