Skip to content
Veltoryx Technologies
ProProblem 130● Mediumleetcode ↗4 min readUpdated 30 October 2026

Surrounded Regions

Capture enclosed board regions by flooding inward from border 'O' cells.

01The problem

Given an m x n matrix board containing 'X' and 'O', capture all regions that are 4-directionally surrounded by 'X'.

A region is captured by flipping all 'O's into 'X's in that surrounded region. Any 'O' that is on the border, or is connected 4-directionally to a border 'O', cannot be captured.

Modify board in-place.

Loading the rest of the lesson…