← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Given a binary matrix containing only '1's and '0's, find the largest square or rectangle containing only '1's and return its area.
This problem has two parts:
Maximal Square: Find the largest square (width = height)
Maximal Rectangle: Find the largest rectangle (width can differ from height)
Both problems require dynamic programming techniques but use different approaches.
` matrix = [ ["1","0","1","0","0"], ["1","0","1","1","1"], ["1","1","1","1","1"], ["1","0","0","1","0"] ]
maximalSquare(matrix) # Returns 4
`
` matrix = [ ["1","0","1","0","0"], ["1","0","1","1","1"], ["1","1","1","1","1"], ["1","0","0","1","0"] ]
maximalRectangle(matrix) # Returns 6
`
m == matrix.length
n == matrix[i].length
1 <= m, n <= 300