FastPrepMaximal Square
Problems/Maximal Square

Maximal Square

Airwallex logoAirwallex● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names this well-known problem directly.

Our version is about 99% the same as the reported question.

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[][]) → 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
matrix
01234010100110111211111310010

The largest all-one square has side length 2, so its area is 4.

Example 2

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

Each '1' cell forms a square of side length 1, and no larger all-one square exists.

Example 3

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

The matrix contains no '1' cell, so the maximum area is 0.

Constraints

  • 1 <= m, n <= 300.
  • m == matrix.length and n == matrix[i].length.
  • Every matrix[i][j] is either '0' or '1'.

More Airwallex interview questions

  • 4Sum Index QuadruplesPHONE SCREEN · Seen Sep 2026
  • Paginated K-Way Unique MergePHONE SCREEN · Seen Sep 2026
  • Largest Rectangle in HistogramPHONE SCREEN · Seen Aug 2026
  • Named Async Task SchedulerOA · Seen Oct 2026

Similar questions at other companies

  • Find Robots by Blocker DistancesUber · PHONE SCREENUber interview questions
  • Factory Cost — Minimum Cost Across StagesStripe · PHONE SCREENStripe interview questions
  • Path Through an O/X Grid Using Only Right and DownAmazon · PHONE SCREEN
  • Maximum Rocks on a North-or-East Grid PathGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Maximal SquareSalesforce · PHONE SCREENSalesforce interview questions
  • Minimum Path SumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Maximum Falling Path SumIMC Trading · PHONE SCREENIMC Trading interview questions
  • Grid Paths Around Blocked CellsAdobe · PHONE SCREENAdobe interview questions
  • Largest Diamond of Ones in a GridRippling · PHONE SCREENRippling interview questions
  • Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW
All Airwallex interview questionsSee Airwallex hiring insights
Saved
class Solution {
    public int maximalSquare(char[][] matrix) {
        // Write your code here.
    }
}
Checking account…