← Questions
Max area of island
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Amazon's online assessment and at Meta, last asked Mar 2026. It tests grids, dfs and bfs.
Given a grid of 0s and 1s, return the area of the largest island. An island is a group of 1 cells joined through shared edges (up, down, left, right); diagonal contact doesn't join them. Its area is its number of cells. A grid with no land, or no cells at all, returns 0.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
max_island_area(grid: list[list[int]]) -> int— do not modifygrid, or say so if you do.
Example
max_island_area([[1, 1, 0],
[0, 1, 0],
[1, 0, 1]]) -> 3 # the top-left island; the others have one cell each
max_island_area([[1, 0],
[0, 1]]) -> 1 # diagonal cells don't connect
max_island_area([]) -> 0
Constraints
- The grid is rectangular; plan for up to 1000 × 1000 cells.
Clarifying questions
- Four-way or eight-way connectivity?
- May I mark visited cells in the input?
- Can the grid be empty, or have empty rows?
What a strong answer covers
- Flood fill from each unvisited
1(BFS, iterative DFS, or union-find), counting cells. - An explicit stack or queue, since recursion can overflow on a large island.
- O(rows · cols) time; O(rows · cols) space for visited, or O(1) extra by marking the grid.
- Tests: all water, all land, one long snake-shaped island.
Follow-ups
- Rows arrive one at a time and you can't keep the whole grid: maintain the largest area with union-find over the current row's components.
- Flip one
0to1to make the largest island possible. - Count the islands of each size.
Where it's asked
- Amazon · Online assessment · Last asked Mar 2026Coding problems plus a repository bug-fix section with a built-in assistant or a design scenario, then a work-style survey · AI only inside the bug-fix section's built-in assistant
- Meta · Technical phone screen · Last asked Sep 202545 min · Two coding problems in CoderPad, about 20 minutes each · Usually no AI; some newer screens are AI-assisted
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding

