FastPrepLargest All-One Square Area
Problems/Largest All-One Square Area

Largest All-One Square Area

Google logoGoogle● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The author described a very similar interview question, not the exact statement. The report asks for the largest square of all ones. Here we say that the function returns the area, and we set the size limits. Our version is about 95% the same as the reported question.

You are given a nonempty rectangular binary matrix matrix. Find the largest square whose cells all contain 1, and return its area.

A square uses consecutive rows and consecutive columns. Return 0 when the matrix contains no 1.

Function

maximalSquareArea(matrix: int[][]) → int

Examples

Example 1

matrix = [[1,1,1],[1,1,1]]return = 4
matrix
01201111111

A square can have side length 2, even though the all-one rectangle is wider.

Example 2

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

There are two overlapping squares of side length 2; the whole matrix is not all ones.

Example 3

matrix = [[0,0],[0,0]]return = 0
matrix
01000100

No all-one cell exists, so the largest square has area 0.

Constraints

  • 1 <= matrix.length, matrix[0].length <= 300.
  • Every row has the same length.
  • Every cell is 0 or 1.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Unique Grid PathsMorgan Stanley · PHONE SCREENMorgan Stanley interview questions
  • Count Starts Reaching a Grid MaximumDuolingo · PHONE SCREENDuolingo interview questions
  • 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
  • 3D Grid Diagonal Walk ProbabilityApple · PHONE SCREENApple interview questions
  • Maximum Rocks on a North-or-East Grid PathGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Maximal SquareAirwallex · PHONE SCREENAirwallex interview questions
  • Maximal SquareSalesforce · PHONE SCREENSalesforce interview questions
  • Maximum Grid Path ScoreDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int maximalSquareArea(int[][] matrix) {
        // Write your code here
    }
}
Checking account…