Skip to main content

Surrounded Regions

Given a matrix of 'X' and 'O' characters Capture (flip to 'X') all regions that are completely surrounded by 'X' A region is NOT surrounded if it touches the border Return the modified board Example: [["X","X","X"],["X","O","X"],["X","X","X"]] => [["X","X","X"],["X","X","X"],["X","X","X"]]

Surrounded Regions is a traversal problem: the hard part is modeling the state you visit. Interviewers love it because it reveals your traversal modeling and your edge-case discipline. Once your traversal structure is solid, you can reuse it across dozens of problems.

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit, and to talk with her for one hour. After that, talking comes with the $79 pack. Anyone can open the editor and run their code.

1Capture Surrounded Regionsmedium
Based onLeetCode

Get a note when something new lands

New company guides, new problems and big changes to Coco. Rare, and you can leave any time. By joining you agree to get these emails.