All problems
Largest Region Size
Problem
Find the size of the largest 4-connected region of ones in a binary grid.
grid is a rectangular list of rows holding only 0 and 1. Flood fill every unvisited land cell and keep the biggest region size seen. Return 0 when the grid contains no ones at all.
Hint
Mark cells when you push them so diagonally touching regions stay separate.
Test cases
case 1
in: [[[1,1,0],[1,0,1],[0,0,1]]]
expected: 3
case 2
in: [[[0,0],[0,0]]]
expected: 0
case 3
in: [[[1,1],[1,1]]]
expected: 4
case 4
in: [[[1,0,0,1]]]
expected: 1
case 5
in: [[[1]]]
expected: 1
Starter codePython
def largest_region_size(grid):
# Your code here
pass5 test cases · run your code against them in the editor