Capture Letter Regions Disconnected from the Board Edge

Quick Overview

Capture only O regions disconnected from every border by marking edge-connected cells and mutating the board.

Capture Letter Regions Disconnected from the Board Edge

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Capture every surrounded region of letter `'O'` cells in a rectangular board of `'X'` and `'O'`. Cells connect horizontally or vertically, not diagonally. A region is surrounded exactly when none of its cells touches the board's outer edge. Change all cells in such regions to `'X'`, leaving other cells unchanged. ```cpp void solve(vector<vector<char>>& board); ``` Mutate the original character matrix; return nothing. Quoted rows below are shorthand for character rows. ### Examples ```text Input rows: ["XXXXX","XOOXX","XXOXX","OXXOX","XXXXX"] Rows after call: ["XXXXX","XXXXX","XXXXX","OXXXX","XXXXX"] ``` The left-edge O survives; the other O regions have no edge connection. ```text Input rows: ["OOO"] Rows after call: ["OOO"] ``` ### Constraints - Both row and column counts are between 1 and 200. - Every original cell is `'X'` or `'O'`.

Overview: Capture only O regions disconnected from every border by marking edge-connected cells and mutating the board.

Amazon logo
Amazon
Date not reported
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Capture every surrounded region of letter 'O' cells in a rectangular board of 'X' and 'O'. Cells connect horizontally or vertically, not diagonally. A region is surrounded exactly when none of its cells touches the board's outer edge. Change all cells in such regions to 'X', leaving other cells unchanged.

void solve(vector<vector<char>>& board);

Mutate the original character matrix; return nothing. Quoted rows below are shorthand for character rows.

Examples

Input rows: ["XXXXX","XOOXX","XXOXX","OXXOX","XXXXX"]
Rows after call: ["XXXXX","XXXXX","XXXXX","OXXXX","XXXXX"]

The left-edge O survives; the other O regions have no edge connection.

Input rows: ["OOO"]
Rows after call: ["OOO"]

Constraints

  • Both row and column counts are between 1 and 200.
  • Every original cell is 'X' or 'O' .