InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Capture Regions on Board

Given a 2D board 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.

Input Format:

    First and only argument is a N x M character matrix A

Output Format:

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


    1 <= N,M <= 1000

For Example:

Input 1:
    A = [ [X, X, X, X],
          [X, O, O, X],
          [X, X, O, X],
          [X, O, X, X] ]
Output 1:
    After running your function, the board should be:
    A = [ [X, X, X, X],
          [X, X, X, X],
          [X, X, X, X],
          [X, O, X, X] ]
    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