Island Perimeter
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 rectangular grid where grid[r][c] == 1 is land and 0 is water. Cells connect only horizontally and vertically. The grid contains exactly one island (one or more connected land cells), and everything outside the grid is water.
Each cell is a square with side length 1. Return the perimeter of the island, i.e. the number of unit edges that separate a land cell from water or from the outside of the grid. Water enclosed inside the island still counts as water.
Examples
Constraints
- 1 <= grid.length, grid[i].length <= 100
- grid[r][c] is 0 or 1
- There is exactly one island
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.