Making A Large 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 an n x n binary grid where 1 is land and 0 is water. An island is a group of land cells connected edge-to-edge (up, down, left, right), and its size is its number of cells.
You may change **at most one** 0 into a 1. Return the size of the largest island possible after the change (or with no change, if that is already best).
Aim for O(n²) time; recomputing islands for every candidate flip is too slow at the upper limit.
Examples
Constraints
- n == grid.length == grid[i].length
- 1 <= n <= 500
- grid[i][j] is 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.