Maximum Area of Island
Reported by candidates from Skydio's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that sinks a naive solution on this Skydio OA, reported in October 2021, is the grid with no land at all. Return 0, not some uninitialized max. Maximum Area of Island is a flood-fill problem: scan the matrix, and when you hit a 1, count every orthogonally connected 1 and track the biggest count. BFS or DFS both work. It looks easy, and that's the trap, because small bookkeeping mistakes cost you hidden test cases. If you freeze on the live assessment, StealthCoder runs invisibly as a safety net and gives you the solution in real time.
The problem
Given a rectangular binary matrix grid, return the maximum area of an island. An island is a maximal group of cells containing 1 connected horizontally or vertically. Its area is its number of cells. Return 0 when the matrix contains no land. Function maxIslandArea(grid: int[][]) → int Examples Example 1 grid = [[0,0,1,0],[1,1,1,0],[0,1,0,1]] return = 5 The center island contains five orthogonally connected land cells. The bottom-right cell is a separate island of area 1. Example 2 grid = [[0,0],[0,0]] return = 0 There are no land cells. Constraints 1 <= grid.length, grid[i].length <= 300. Every row has the same length. grid[i][j] is either 0 or 1.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to visit each cell once. Loop over every cell. When you find a 1, start a BFS or DFS, count the cells you reach, and mark each as visited as you go. Either flip it to 0 in place or keep a visited array. Then update your running max. Initialize the max to 0 so an all-water grid returns 0 correctly. The common pitfalls are counting diagonal neighbors (only four directions are allowed), forgetting to mark visited before pushing onto the queue so cells get counted twice, and blowing the recursion stack with DFS on a 300 by 300 grid full of land. An iterative BFS or an explicit stack avoids that. Time is O(rows times cols). If you blank during the live OA, StealthCoder is the hedge that reads the problem and hands you a working flood fill.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Maximum 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as max area of island. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Skydio's OA.
Skydio reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Area of Island FAQ
How hard is Maximum Area of Island really?+
It's a standard medium-level grid traversal. The logic is simple: find a 1, flood fill, count, track the max. Most failures come from bookkeeping errors like double counting or missing the all-zero grid, not from the algorithm itself.
What's the trick to solving it fast?+
Mark cells visited the moment you enqueue or enter them, ideally by setting them to 0 in place. Then every cell is processed once, and a single outer double loop with a running max gives you the answer in O(rows times cols).
BFS or DFS, which should I use here?+
Either is correct. With a grid up to 300 by 300, recursive DFS can hit 90,000 levels deep and overflow the stack in some languages. Iterative BFS with a queue, or DFS with an explicit stack, is the safer pick.
What edge cases should I test before submitting?+
Test an all-zero grid, which must return 0. Test an all-ones grid, where the answer is rows times cols. Test a single cell grid, and a case where land touches only diagonally, which must count as separate islands.
How do I prepare for this in 48 hours?+
Write the flood fill from scratch twice on a blank editor. Use the four-direction array and bounds checks. Then try a variant, like counting islands or returning the largest one's coordinates. Once the pattern feels automatic, you're ready for this Skydio style question.