Problem · Array

Maximal Square

Learn this problem
MediumAmazonONSITE INTERVIEW
See Amazon hiring insights

Problem statement

Given a matrix of characters '0' and '1', return the area of the largest square containing only '1' cells.

Function

maximalSquare(matrix: char[][]) → int

Examples

Example 1

matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]return = 4

The largest all-one square has side length 2.

Example 2

matrix = [["0"]]return = 0

More Amazon problems

drafts saved locally
public int maximalSquare(char[][] matrix) {
  // write your code here
}
matrix[["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
expected4
checking account