Reported May 2026
Uberdynamic programming

Maximal Square Area

Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Uber OA. Under 2s to a working solution.
Founder's read

You're facing Uber's Maximal Square problem in May 2026. This is a classic dynamic programming trap that looks deceptively simple: given a grid of 0s and 1s, find the biggest square of all 1s and return its area. Most candidates start with brute force or flawed greedy logic and time out. The pattern is DP with bottom-up state tracking. StealthCoder will catch you if you blank on the recurrence relation during the live OA.

The problem

Complete the function below. The function receives the full standard input as a single string and must return the exact standard output lines for the described problem. Problem Given an m x n matrix of characters '0' and '1', find the largest square containing only '1's and return its area. Input First line: two integers m n Next m lines: each is a length-n string containing only 0/1 Output A single integer: the maximal square area Constraints 1 <= m, n <= 300 Examples 4 5 10100 10111 11111 10010 Output: 4 2 2 00 Output: 0 Example Input 4 5 10100 10111 11111 10010 Output 4 Function Description Complete solveMaximalSquareArea. It has one parameter, String input, containing the full stdin payload. Return the stdout payload as an array of lines, without trailing newline characters. The returned string array must match the expected standard output lines for the sample input. Use the limits and requirements stated in the prompt.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is building a DP table where dp[i][j] represents the side length of the largest square with bottom-right corner at (i, j). For each cell, if it's a 1, you check the minimum of the three neighbors (top, left, top-left) and add 1. If it's a 0, the value is 0. The answer is the maximum dp value squared. Naive O(m*n^2) scanning fails at m, n = 300. The DP approach runs O(m*n) time and O(m*n) space. Common pitfall: off-by-one indexing and confusing side length with area. StealthCoder is your safety net if the state transition goes fuzzy under pressure.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Maximal Square Area cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as maximal square. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Uber's OA.

Uber reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximal Square Area FAQ

Is this actually a DP problem or can greedy work?+

Pure DP. Greedy fails because a 1 at position (i, j) doesn't tell you the largest square ending there. You must know the max square size from all three neighbors to compute the current cell correctly.

What's the recurrence relation exactly?+

If grid[i][j] == '1', then dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1. Otherwise dp[i][j] = 0. The answer is max(dp) squared.

How do I handle the first row and first column?+

First row and column can only have squares of size 1 (if the cell is '1'). Initialize them separately or handle them as base cases in the recurrence. Off-by-one errors here kill submissions.

Can I optimize space below O(m*n)?+

Yes, to O(n) by keeping only the previous row. But at m, n = 300, O(m*n) is safe and faster to code correctly. Don't optimize prematurely during the OA.

What if the entire grid is 0s or there's no square of size > 1?+

Return 0 if no 1 exists, or 1 if at least one 1 exists. Edge cases: empty grid (return 0), single cell (return 1 if it's a 1, else 0).

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Uber.

OA at Uber?
Invisible during screen share
Get it