N = 3 and M = 3
Required Matrix-
XXX
XOX
XXX
The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow.
The first line of each test case contains two integers ‘N’ and ‘M’ denoting the number of rows and columns in the required matrix.
For each test case print 'N' strings denoting 2D matrix satisfying the above conditions.
You are not required to print anything; it has already been taken care of. Just implement the function and return the matrix.
1 <= T <= 50
1 <= N <= 100
1 <= M <= 100
Time Limit: 1 sec.
We can see that for, given ‘N’ and ‘M’, we have exactly (min('N', ‘M’) + 1) / 2 rectangles to fill. So, we can iterate through each and every rectangle starting from the outermost one and fill it with the required character.
Ninja and the experiment
Star Triangle
Search In A Sorted 2D Matrix
Spiral Matrix
Spiral Matrix
Spiral Matrix
Find the maximum element of each row
Find the maximum element of each row