Surrounded Regions
A medium-tier problem at 43% community acceptance, tagged with Array, Depth-First Search, Breadth-First Search. Reported in interviews at Urban Company and 5 others.
Surrounded Regions hits your assessment when the interviewer wants to see if you can flip a grid problem on its head. Google, TikTok, and Flipkart ask it. The naive approach costs you: most candidates try marking from the inside out, which is backwards and inefficient. The trick is inverted thinking: start from the borders, mark everything reachable from the edges as safe, then flip the rest. It's a medium-difficulty problem but the conceptual flip trips up 57% of candidates. If this pattern lands on your live OA and the obvious direction fails, StealthCoder surfaces the working solution in seconds while you stay invisible to the proctor.
Companies that ask "Surrounded Regions"
Surrounded Regions is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe problem presents a matrix where you must flip regions of 'O' to 'X', but only if they're completely surrounded. The inefficient path is DFS or BFS from each internal 'O' to check if it reaches a boundary. The actual solution inverts the search: start DFS or BFS from every 'O' on the border and mark all connected 'O's as untouchable. Anything still unmarked is surrounded and gets flipped. Union Find is another valid approach but overkill for most interviewers. The real pitfall is not thinking about boundary-first logic early. You can also solve it with BFS if DFS blows the stack on large grids. Common mistake: trying to track which regions are surrounded rather than which are safe. When you hit a wall in the live assessment, StealthCoder handles the graph traversal and flip logic while you keep your screen clean.
Pattern tags
You know the problem.
Make sure you actually pass it.
Surrounded Regions recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Surrounded Regions interview FAQ
Is this still asked at FAANG companies?+
Yes. Google and TikTok report it frequently. It's a classic medium that tests whether you can invert a problem conceptually, not just code a traversal. Interviewers like it because many candidates default to forward logic and miss the border-first insight.
What's the actual trick everyone misses?+
Starting from the borders, not the interior. Mark all 'O's reachable from the edges as safe, then flip everything else. It flips the problem from 'find surrounded regions' to 'find safe regions,' which is far simpler and faster than checking each region independently.
DFS or BFS for this one?+
Either works. DFS is shorter to write but can stack overflow on very large grids. BFS is safer if you're nervous about recursion depth limits. The interviewer usually doesn't care which you pick as long as you acknowledge the trade-off.
Why is the acceptance rate only 43%?+
The conceptual flip is genuinely hard to spot under time pressure. Candidates often get the traversal right but solve the wrong subproblem. Medium difficulty plus that unintuitive inversion makes it a stumbling block in live assessments.
Do I need Union Find for this?+
No. Union Find is elegant but overkill. DFS or BFS from the borders is simpler, faster to code, and what most interviewers expect. Save Union Find for problems where you actually need to merge disjoint sets.
Want the actual problem statement? View "Surrounded Regions" on LeetCode →