Maximal Square
Given an m x n binary matrix of '0' and '1' characters, find the largest square whose cells are all '1' and return its area.
Open official problem prompt ↗Determine the area of the biggest square block containing only 1s inside a binary grid.
Laying square tiles on a floor of good (1) and broken (0) planks. A tile of side k fits at a corner only if the three tiles touching its top, left, and diagonal already fit at side k-1; the weakest neighbor limits how big you can go.
- Input
- matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
- Output
- 4
- Why
- The largest all-ones square has side 2 (area 4), formed in the lower-middle block of 1s.
m == matrix.lengthn == matrix[i].length1 <= m, n <= 300matrix[i][j] is '0' or '1'