Maximal Square
A medium-tier problem at 49% community acceptance, tagged with Array, Dynamic Programming, Matrix. Reported in interviews at BharatPe and 21 others.
Maximal Square hits your screen and you've got a matrix filled with 1s and 0s. Find the largest square submatrix of all 1s. Sounds simple until you realize brute force will time out. BharatPe, Wise, ServiceNow, PayPal, Airbnb, and ByteDance all ask this. Nearly 49% of candidates solve it, which means half don't. If you blank on the DP trick, StealthCoder surfaces the working solution in seconds while you're in the live OA, invisible to the proctor.
Companies that ask "Maximal Square"
Maximal Square is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.
Get StealthCoderThe trick is dynamic programming on a 2D table, not greedy expansion or matrix scanning. Build a DP array where each cell stores the side length of the largest square with bottom-right corner at that position. For each cell, if it's a 1, the new square side length is 1 plus the minimum of the three neighbors (left, top, diag top-left). Most candidates try to expand outward from each 1 or check every possible square, both of which fail on large matrices. The DP solution is O(m*n) time and space. When you hit this live and the obvious approach isn't working, StealthCoder runs the pattern instantly so you move forward.
Pattern tags
You know the problem.
Make sure you actually pass it.
Maximal Square recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximal Square interview FAQ
Is Maximal Square still asked at top companies?+
Yes, frequently. PayPal, Airbnb, ServiceNow, and ByteDance all report asking it. It's a stable medium-difficulty DP problem for screening rounds. At 49% acceptance, it's not a gimme, so preparation matters.
What's the core trick I need to know?+
DP table where dp[i][j] = side length of the largest square ending at (i,j). Update rule: if matrix[i][j] is 1, dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]). The minimum of three neighbors is the bottleneck that determines the largest valid square.
How does Maximal Square relate to the other Matrix and DP topics?+
It combines matrix iteration with DP state transition. You're building on prior subproblems in both dimensions, which is the essence of 2D DP. Understanding this pattern transfers to Largest Rectangle in Histogram and other spatial DP problems.
Why do so many candidates fail this?+
They try greedy expansion from each 1 or brute force every possible square. Both fail on time. The DP insight, that you can reuse three neighbors' results, isn't obvious until you've seen it. That's exactly when StealthCoder steps in during the live OA.
What's the space optimization if I get asked?+
You can reduce from O(m*n) to O(n) by keeping only the current and previous row of the DP table. Rarely asked at the medium level, but good to mention if the interviewer digs deeper into your solution.
Want the actual problem statement? View "Maximal Square" on LeetCode →