Reported October 2026
Amazonbreadth first search

Max Area of Island

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Brute force dies the moment you re-count the same land cells from every starting point, and Amazon's October 2026 report of Max Area of Island is built to punish that. You get a binary matrix, you return the biggest group of orthogonally connected 1s. The example gives 5 for the center blob, with the lower-right cell stranded on its own. It's a flood-fill problem wearing a matrix costume. If you blank on the traversal mid-OA, StealthCoder is the invisible safety net sitting on your screen, but the pattern below is short enough to own tonight.

The problem

Given a binary matrix grid, return the maximum area of an island.

Examples
Example 1
grid = [[0,0,1,0],[1,1,1,0],[0,1,0,1]]
return = 5
The center component has five orthogonally connected land cells. The lower-right cell is separate.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is visiting each cell once. Scan the grid. When you hit a 1, start a BFS or DFS from it, count every connected 1, and mark cells visited as you go. Flip them to 0 in place, or use a visited set. Track the max count across all starts. That's O(rows * cols) time. The pitfalls are small but costly. Don't include diagonals, because the example explicitly says orthogonal. Don't forget to mark a cell visited when you push it onto the queue, not when you pop it, or you'll double count. Recursive DFS can overflow the stack on a big grid, so BFS with a queue is safer. Handle an all-zero grid by returning 0. If the traversal slips away from you during the live OA, StealthCoder can hand you the working version.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Max Area of Island cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as max area of island. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Max Area of Island FAQ

How hard is Max Area of Island really?+

It's a medium at most. If you've written a flood fill once, you can write this in ten minutes. The only new part is returning a count from each traversal and keeping a running max. Most failures come from sloppy visited handling, not from the idea.

What's the trick to avoid recounting cells?+

Mark cells as visited the moment you touch them. Setting grid[r][c] = 0 in place works and needs no extra set. Then the outer scan can skip them naturally, and every cell gets processed once, giving linear time in the grid size.

BFS or DFS for this one?+

Either works and the complexity is identical. DFS is shorter to write recursively, but deep islands can blow the stack. BFS with a queue avoids that. Pick whichever you can write without bugs under pressure, and stay consistent.

Do diagonal cells count as connected?+

No. The example says orthogonally connected, so only up, down, left, and right neighbors count. In the sample, the lower-right 1 is not joined to the center blob, which is why the answer is 5. Use four direction offsets, not eight.

How do I prepare in 48 hours?+

Write the BFS version from scratch twice, then the DFS version once. Test on an all-zero grid, a single cell, and the sample. Then do one variant like counting islands. Focus on bounds checks and visited marking, since those cause most wrong answers.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it