InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

Capture Regions on Board

Problem Description

Given a 2D character matrix A of size N x M, containing 'X' and 'O', capture all regions surrounded by 'X'.

A region is captured by flipping all 'O's into 'X's in that surrounded region.

Problem Constraints

1 <= N, M <= 103

Input Format

First and only argument 2D character matrix A of size N X M.

Output Format

Make changes to the the input only as matrix is passed by reference.

Example Input

Input 1:

 A = [  [X, X, X, X],
        [X, O, O, X],
        [X, X, O, X],
        [X, O, X, X]

Example Output

Output 1:

 A = [  [X, X, X, X],
        [X, X, X, X],
        [X, X, X, X],
        [X, O, X, X]

Example Explanation

Explanation 1:

 'O' in (4,2) is not surrounded by X from below.

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Capture Regions on Board on Interview Code Editor
Sign Up
to access hints and editorial solutions for Capture Regions on Board
Asked In:


Click here to start solving coding interview questions