Capture Enclosed Regions on a Board That Never Touch the Edge
Last updated: November 29, 2026
Quick Overview
A board of 'X' and 'O' cells represents territory in a strategy game. Flip every 'O' region that is fully surrounded by 'X' (not 4-connected to any border 'O') to 'X', in place.
Meta
November 29, 20260
0
0 solved
A board of 'X' and 'O' cells represents territory in a strategy game. Flip every 'O' region that is fully surrounded by 'X' (not 4-connected to any border 'O') to 'X', in place.
An in-place grid problem in the style of Meta's technical screen, framed around a territory-capture rule in a casual game on Facebook Gaming. The interviewer checks whether you invert the question and mark the safe regions from the border, rather than testing every region for enclosure.
What the Interviewer Expects
- Starts from border 'O' cells instead of interior ones
- Marks safe cells with a temporary symbol
- Flips remaining 'O' to 'X' and restores safe cells in one final pass
- Uses iterative traversal to avoid recursion limits
- Handles boards with one row or column
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you count the captured regions?
- What if diagonal connectivity also counts?
- How would you do it with union-find?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: mutable list-of-lists board with 'X' and 'O'. Output: none, modify in place. An 'O' survives if it can reach a border 'O' through 4-directional 'O' moves. Boards up to 200 x 200....
High-Level Design
Any 'O' connected to the border is safe; every other 'O' is captured. So run a traversal from every border 'O' and mark reachable 'O' cells as 'S'. Then sweep the board: 'O' becomes 'X' (captured) and...