Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

You are given two integers N and M. You are required to return the matrix of size N * M characters such that every element of the matrix can be X or O, and it must satisfy the following condition.

The Xs and Os must be filled. Alternatively, the matrix should have the outermost rectangle of Xs, then a rectangle of Os, then a rectangle of Xs, and so on.

```
N = 3 and M = 3
Required Matrix-
XXX
XOX
XXX
```

Detailed explanation

```
1 <= T <= 50
1 <= N <= 100
1 <= M <= 100
Time Limit: 1 sec.
```

```
2
4 4
3 4
```

```
XXXX
XOOX
XOOX
XXXX
XXXX
XOOX
XXXX
```

```
In test case 1:
N is 4 and M is also 4, so a matrix of size 4 * 4 is required to output. In the matrix, the outermost rectangle is filled with X and then adjacent to it with O and so on.
Hence the required matrix will be :
XXXX
XOOX
XOOX
XXXX
In test case 2:
N is 3 and M is also 4, so a matrix of size 3 * 4 is required to output. In the matrix, the outermost rectangle is filled with X and then adjacent to it with O and so on.
Hence the required matrix will be :
XXXX
XOOX
XXXX
```

```
2
5 3
1 2
```

```
XXX
XOX
XOX
XOX
XXX
XXX
```