Problem · Array
Maximal Square
Learn this problemProblem statement
Given an m x n binary matrix containing the characters '0' and '1', return the area of the largest square whose cells are all '1'.
Function
maximalSquare(matrix: char[][]) → intExamples
Example 1
matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]return = 4The largest all-one square has side length 2, so its area is 4.
Example 2
matrix = [["0","1"],["1","0"]]return = 1Each '1' cell forms a square of side length 1, and no larger all-one square exists.
Example 3
matrix = [["0"]]return = 0The matrix contains no '1' cell, so the maximum area is 0.
Constraints
m == matrix.lengthn == matrix[i].length1 <= m, n <= 300- Each
matrix[i][j]is either'0'or'1'.
More Salesforce problems
- Longest Increasing SubsequencePHONE SCREEN · Seen Jul 2026
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026