FastPrepMaximal Square
Problems/Maximal Square

Maximal Square

Amazon logoAmazon● MediumONSITE INTERVIEW
QuestionFunctionExamples

Problem statement

Source note: This problem is backed by a real Amazon onsite interview report. The report directly named Maximal Square, but it did not include the exact interface, examples, or constraints. The core task match is about 95%.

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

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int maximalSquare(char[][] matrix) {
      // write your code here
    }
}
Checking account…