maxSquareLength to 0 to keep track of the maximum length of a square found so far.dp with the same dimensions as the input matrix, initialized to 0.(i, j) in the input matrix.
a. If matrix[i][j] is 1, update dp[i][j] to min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1.
b. Update maxSquareLength to the maximum of its current value and dp[i][j].maxSquareLength * maxSquareLength.