Largest 1-Bordered Square
A medium-tier problem at 51% community acceptance, tagged with Array, Dynamic Programming, Matrix. Reported in interviews at ZS Associates and 2 others.
You've seen matrix problems before. This one asks you to find the largest square in a 2D grid where every border cell is 1 and the interior can be anything. ZS Associates, Samsung, and DE Shaw have all asked it. The acceptance rate hovers just above 50%, which means half the candidates who attempt it walk away empty-handed. The trick isn't immediately obvious from the problem statement, and a brute-force scan will either time out or push you into edge-case hell. If this lands in your assessment and you freeze on the pattern, StealthCoder solves it invisibly in seconds, leaving you unblocked.
Companies that ask "Largest 1-Bordered Square"
Largest 1-Bordered 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. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe core insight is that you're not checking every possible square naively. Instead, you precompute horizontal and vertical runs of consecutive 1s at every position using dynamic programming. For a square of side length k to be valid, you need at least k consecutive 1s on all four borders. The DP tables let you verify borders in O(1) time per candidate square, reducing the overall complexity from cubic to quadratic. Most candidates either miss the precomputation step and time out, or they precompute but then check borders wrong (forgetting corner cells, or mixing up coordinate transforms). The other gotcha is recognizing that a 1x1 grid of a single 1 is valid. When this problem appears live, StealthCoder surfaces a working DP solution with correct border logic, so you're not spending fifteen minutes debugging whether corners count.
Pattern tags
You know the problem.
Make sure you actually pass it.
Largest 1-Bordered 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. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Largest 1-Bordered Square interview FAQ
Is this problem still asked at ZS Associates, Samsung, or DE Shaw?+
Yes. All three companies are in the recent ask history for this problem. It's a medium-difficulty matrix DP classic, not some obscure variant. Expect it if you're interviewing with any of them.
Can you solve it with a simple nested loop over all squares?+
Not within time limits. Checking every square naively and validating its borders each time is O(n^4) or worse. You need DP precomputation of horizontal and vertical 1-runs to drop to O(n^3) or better.
What's the trick most people miss?+
They forget to precompute the consecutive 1s correctly, or they mess up the coordinate math when checking borders. The border of a kxk square at position (r,c) spans four edges; getting the indices wrong derails the whole solution.
How does Dynamic Programming actually help here?+
You build lookup tables for the longest run of 1s going right and down from each cell. Then instead of scanning a border cell by cell, you check the precomputed run length in O(1). This collapse of border validation from O(k) to O(1) is what makes the algorithm feasible.
Are there any edge cases that break common solutions?+
A 1x1 grid containing a single 1 counts as a valid bordered square. Empty grids, grids with no 1s, and single-row/single-column grids are also common traps if your boundary conditions aren't tight.
Want the actual problem statement? View "Largest 1-Bordered Square" on LeetCode →