FastPrepMaximal Square Area
Problems/Maximal Square Area

Maximal Square Area

Uber logoUber● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a grid of characters, matrix. Each cell is either '0' or '1'.

Find the largest square that is made only of '1' cells. Return its area. A square with side k has area k * k.

If the grid has no '1' at all, return 0.

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 grid has 4 rows and 5 columns. Rows 2 and 3 (counting from 1) both have 1s in columns 3 and 4, so those four cells form a square with side 2. No square with side 3 is all 1s, because every 3 by 3 block of this grid holds at least one 0. The best side is 2, so the area is 2 * 2 = 4.

Constraints

  • 1 <= matrix.length <= 300
  • 1 <= matrix[i].length <= 300
  • Every row of matrix has the same length
  • Each matrix[i][j] is '0' or '1'

More Uber Onsite Interview questions

  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Online Meeting Scheduler with Fixed RoomsONSITE INTERVIEW · Seen Oct 2026
  • Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Serialize and Deserialize an N-Ary TreeONSITE INTERVIEW · Seen Oct 2026
  • Longest Continuous Subarray Within an Absolute-Difference LimitONSITE INTERVIEW · Seen Oct 2026
  • K Smallest Squares from a Sorted ArrayONSITE INTERVIEW · Seen Sep 2026
  • Grid Robot Route with Charging PrioritiesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Shortest Increasing Path to a TargetONSITE INTERVIEW · Seen Sep 2026
  • My Calendar IONSITE INTERVIEW · Seen Sep 2026
  • Per-Element Hit CounterONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
  • Knight Probability in ChessboardGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Longest Matrix Walk with Two-Step ComparisonsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Maximum All-Ones Square Side LengthOmnissa · ONSITE INTERVIEWOmnissa interview questions
  • Enumerate Right-and-Down Matrix PathsOracle · ONSITE INTERVIEWOracle interview questions
  • Minimum Path SumMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Maximum Grid Path ScoreDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Minimum Path SumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Bomb Enemy Best CoordinatesSambaNova Systems · ONSITE INTERVIEWSambaNova Systems interview questions
  • Maximum Falling Path Sum in a RectanglePeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public int maximalSquare(char[][] matrix) {
        // write your code here
    }

}
Checking account…