Maximal Square
Return the area of the largest square containing only 1s.
Examples
Input: ["10100","10111","11111","10010"]
Output: 4
Input: ["0"]
Output: 0
Hints
Initialize a DP table where `dp[i][j]` represents the side length of the largest square ending at `(i, j)`. Set `dp[i][j] = 1` if `matrix[i][j] == '1'`, else `0`.
For each cell `(i, j)` in the matrix, if `matrix[i][j] == '1'`, compute `dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])` to determine the largest square ending here.
Track the maximum value in the DP table during iteration. The area of the largest square is `max_side^2`, where `max_side` is the largest value found in the DP table.
Related Problems
Maximal Square
Return the area of the largest square containing only 1s.