Skip to content

Surrounded Regions

MediumGraphs
Decode it first. Clues, constraints, pattern and plan before any code.

A board holds "X" and "O" cells. A group of "O" cells connected up, down, left or right is captured when none of its cells lies on the edge of the board: flip every cell of a captured group to "X". Groups that touch the border survive. Change board in place; the function returns nothing.

X X X X        X X X X
X O O X   →    X X X X
X X O X        X X X X
X O X X        X O X X   (the bottom O touches the border, so it stays)

Constraints

  • 1 <= board.length, board[i].length <= 200
  • board[i][j] is "X" or "O"