Remove Captured Stone Groups With No Liberties on a Go Board

Last updated: November 29, 2026

Quick Overview

Given a Go board with 'B', 'W', and '.' cells and the color that just moved, remove every opponent group (4-connected stones of one color) that has no adjacent empty cell, and return the board and number of stones captured.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given a Go board with 'B', 'W', and '.' cells and the color that just moved, remove every opponent group (4-connected stones of one color) that has no adjacent empty cell, and return the board and number of stones captured.

An onsite style question with a nod to DeepMind's work on Go. It tests connected-component discovery on a grid, plus the domain detail that a group lives or dies as a unit based on its liberties, and the interviewer wants clean separation between finding a group and deciding its fate.

What the Interviewer Expects
  • Find each opponent group with BFS or DFS
  • Track whether any stone in the group touches an empty cell
  • Remove whole groups only after the group is fully explored
  • Mark visited stones so each group is processed once
  • Discuss suicide moves and the order of captures
Key Topics to Cover
connected components
BFS
grid
game simulation
liberties
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
  • After removing captures, check whether the mover's own group is suicidal.
  • How would you detect a ko (immediate recapture repeating the position)?
  • How would you make liberty counting incremental for a game engine doing millions of playouts?
  • Count territory at the end of the game for area scoring.
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: board as list of lists of 'B', 'W', '.', and mover color.
  • Remove every opponent group with zero liberties.
  • Return the number of stones removed; mutate the board in place.
  • Diag...
High-Level Design

Scan every cell. When we meet an unvisited opponent stone, BFS its group, collecting all stones and noting whether any neighbor is '.'. Only after the BFS finishes do we know the group's fate, so I ...


Submit Your Answer
Markdown supported