As reported: Roku Software Engineer loop (2025), DSA round: LeetCode 695 Max Area of Island, followed by Minimum Cost For Tickets.
This is LeetCode 695 — Max Area of Island.
You are given an m × n binary grid. An island is a group of 1s (land) connected 4-directionally (up, down, left, right). The area of an island is its number of cells.
Return the maximum area of an island in grid, or 0 if there is no land.
Example 1
grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],
[0,0,0,0,0,0,0,1,1,1,0,0,0],
[0,1,1,0,1,0,0,0,0,0,0,0,0],
[0,1,0,0,1,1,0,0,1,0,1,0,0],
[0,1,0,0,1,1,0,0,1,1,1,0,0],
[0,0,0,0,0,0,0,0,0,0,1,0,0],
[0,0,0,0,0,0,0,1,1,1,0,0,0],
[0,0,0,0,0,0,0,1,1,0,0,0,0]] -> 6
Diagonal cells do not connect, so the answer is 6, not 11.
Example 2
grid = [[0,0,0,0,0,0,0,0]] -> 0
Constraints: 1 ≤ m, n ≤ 50; grid[i][j] is 0 or 1.
Code runner format: one line holding grid (LeetCode's test-case format). Implement maxAreaOfIsland(grid); the harness prints the area.