You are given a
2D
binary matrix
arr[][]
filled with 0's and 1's. The array contains a square of 1's. So, you need to find that square and return its area.
Example 1
Input:
1 1 1 1 0
1 1 1 1 1
1 1 1 1 1
1 0 1 0 0
Output: 9
Explanation: The largest square in the given matrix has an area of 9 sq. units.
Example 2
Input:
0 0 0 0 1 1
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
1 1 1 1 1 1
1 0 0 0 0 0
Output: 16
Explanation: The largest square in the given matrix has an area of 16 sq. units.