public static void Main()
int[,] map = new int[4,5] { { 0, 0, 1, 1, 0 },
Console.WriteLine(getBiggestRegion(map));
public static int getBiggestRegion(int[,] matrix)
for (int row = 0; row < matrix.GetLength(0); row++)
for (int column = 0; column < matrix.GetLength(1); column++)
if (matrix[row,column] == 1)
int size = getRegionSize(matrix, row, column);
maxRegion = Math.Max(size, maxRegion);
private static int getRegionSize(int[,] matrix, int row, int column)
if (row < 0 || column < 0 || row >= matrix.GetLength(0) || column >= matrix.GetLength(1))
if (matrix[row, column] == 0)
for (int r = row - 1; r <= row + 1; r++)
for (int c = column - 1; c <= column + 1; c++)
if (r != row || c != column)
size += getRegionSize(matrix, r, c);