mediumGraphsAmazon
Captured Region Flipper
A board-game solver flips captured enemy territories to friendly, keeping only groups touching the board edge safe.
Given an m×n matrix of 'X' and 'O', flip every 'O' NOT connected to a border 'O' into 'X'.
Choose approach
X
X
X
X
X
O
O
X
X
X
O
X
X
S
X
X
1/2
Narrationstep 1 of 2
Mark border-connected O's as safe (S).
Variables
stage=mark-safe
How to think about it
- Only border-reachable 'O's survive.
- Mark survivors with a temp sentinel to distinguish from doomed 'O's.
- Final linear pass does the flip.
Edge cases to catch in interview
- Empty grid -> no-op.
- No 'O' touches border -> every O flipped.
Examples
Example 1
unchanged border Os{"grid":[["X","O"],["O","X"]]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed