Maximal Square
Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

30:00

Maximal Square
medium
Topics
Companies

Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.

Example 1:
Input: [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
Output: 4
Constraints:
  • m==matrix.lengthm == \text{matrix.length}

  • n==matrix[i].lengthn == \text{matrix}[i].\text{length}

  • 1m,n3001 \leq m, n \leq 300

  • matrix[i][j]\text{matrix}[i][j] is '0' or '1'.

Input
arr =[["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]

Initialize DP matrix with zeros

Input Matrix

1

0

1

0

0

1

0

1

1

1

1

1

1

1

1

1

0

0

1

0

DP Matrix (max square side)

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

Position:

(-1, -1)

Max Side:

0

Max Area:

0

Current

Input 1

Max Square

Variables
No variables to display
DepthFunction Call
Stack empty
0/14