#K52102. Rectangle Component Checker
Rectangle Component Checker
Rectangle Component Checker
You are given a grid of characters consisting of .
and X
. The grid represents a pattern where the character X
forms a connected component. Your task is to determine whether the connected component of X
forms a perfect rectangle.
A connected component forms a rectangle if, when you determine the minimum and maximum row and column indices that contain an X
, all cells within that defined sub-grid are filled with an X
. If there exists any cell within that rectangle that is not X
, the answer is NO; otherwise, it is YES.
Note: A single X
is considered as a rectangle of size $1\times1$.
inputFormat
The first line of input contains an integer T (the number of test cases).
Each test case starts with a line containing two integers n and m — the number of rows and columns of the grid, respectively.
This is followed by n lines, each containing a string of length m consisting only of characters .
and X
, representing the grid.
Input is read from standard input (stdin).
outputFormat
For each test case, output a single line containing either YES
if the connected component of X
forms a rectangle, or NO
otherwise.
Output should be written to standard output (stdout).
## sample2
4 5
.....
..XX.
..XX.
.....
3 4
..X.
..X.
...X
YES
NO
</p>