Max Area of Island
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a 2D grid grid of size m x n, where each cell holds either 0 (water) or 1 (land).
An **island** is a group of 1 cells that are connected to each other **4-directionally** (up, down, left, and right). You may assume every cell outside the grid's borders is water, so islands never wrap around the edges.
The **area** of an island is simply the number of land cells (1s) that make up that island.
Return the **maximum area** of any island in grid. If the grid contains no land at all, return 0.
Examples
Constraints
- `m == grid.length`
- `n == grid[i].length`
- `1 <= m, n <= 50`
- Each `grid[i][j]` is either `0` or `1`.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.