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

Problem of the day

You have been given a non-empty grid ‘MAT’ consisting of only 0s and 1s. Your task is to find the area of maximum size square sub-matrix with all 1s.

If there is no such sub-matrix, print 0.

For example, for the following grid:

```
The area of the largest square submatrix with all 1s is 4.
```

Detailed explanation

```
1 <= T <= 100
1 <= N <= 50
1 <= M <= 50
0 <= MAT[i][j] <= 1
Time limit: 1 sec
```

```
1
2 2
1 0
0 0
```

```
1
```

```
For the given grid, the largest square with all 1s has a side of length 1. So, the area will be 1 * 1 = 1.
```

```
2
3 4
1 1 1 1
0 1 1 0
0 0 0 0
2 3
0 0 0
0 0 1
```

```
4
1
```