Capture Region Problem Statement
You are given a matrix having N
rows and M
columns. Each cell of the matrix contains either 'X' or 'O'. Your task is to flip all the regions of 'O' that are completely surrounded by 'X'. This means you need to change all 'O's in the surrounded region to 'X'.
Input:
The first line contains an integer 'T' representing the number of test cases.
For each test case, the first line contains two space-separated integers, 'N' and 'M', describing the dimensions of the matrix.
In the next 'N' lines, each line contains a string of length 'M' consisting of 'X' and 'O'.
Output:
For each test case, output the modified matrix with N lines, each containing M characters, where surrounded 'O' regions are flipped to 'X'.
The result of each test case should be printed on a new line.
Example:
Constraints:
1 <= T <= 50
1 <= N <= 10^4
1 <= M <= 10^4
1 <= N * M <= 10^4
Note:
1. O's on the matrix border are not flipped since they are not surrounded.
2. A region of 'O's is considered surrounded if all boundary cells of the region contain 'X'.

AnswerBot
4mo
Given a matrix with 'X' and 'O', flip all 'O' regions completely surrounded by 'X' to 'X'.
Iterate through the matrix and identify 'O' regions completely surrounded by 'X'.
Use DFS/BFS to mark all 'O's ...read more
Help your peers!
Add answer anonymously...
Jupiter Money Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Partial BST Problem Statement Check if a given binary tree is a Partial Binary S...read more
A Software Developer Intern was asked Q. Merge Two Sorted Linked Lists Problem Statement You are provided with two sorted...read more
A Software Developer Intern was asked Q. Shortest Path in an Unweighted Graph The city of Ninjaland is represented as an ...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Partial BST Problem Statement Check if a given binary tree is a Partial Binary S...read more
A Software Developer Intern was asked Q2. Merge Two Sorted Linked Lists Problem Statement You are provided with two sorted...read more
A Software Developer Intern was asked Q3. Shortest Path in an Unweighted Graph The city of Ninjaland is represented as an ...read more
>
Jupiter Money Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

