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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
DFS
Grids
In-place mutation
Boundary search
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported