Description
Given an m x n binary matrix filled with 0s and 1s, find the largest square containing only 1s and return its area.
Examples
Input:
matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]Output:
4Explanation:
2×2 square of 1's.
Input:
matrix = [["1","1","1"],["1","1","1"],["1","1","1"]]Output:
9Explanation:
The entire 3×3 matrix consists of 1's, forming a perfect square. The area of this 3×3 square is 9.
Input:
matrix = [["1","1","0","1"],["1","1","0","1"],["0","0","1","1"],["1","1","1","1"]]Output:
4Explanation:
There are multiple 2×2 squares of 1's possible: top-left corner (positions [0,0] to [1,1]), right side (positions [0,3] to [1,3] - but blocked by 0's), and bottom-right corner (positions [2,2] to [3,3]). The largest square has area 4.
Constraints
- •
1 ≤ m, n ≤ 300