Largest All-Healthy Square Block in a Server Rack Grid

Last updated: November 29, 2026

Quick Overview

A machine room is a grid where 1 marks a healthy server and 0 an unhealthy one. Return the area of the largest square block made entirely of healthy servers, using a DP with O(columns) memory.

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A machine room is a grid where 1 marks a healthy server and 0 an unhealthy one. Return the area of the largest square block made entirely of healthy servers, using a DP with O(columns) memory.

ByteDance's infrastructure team schedules large training jobs that prefer physically contiguous healthy machines to reduce network hops. This grid DP checks that you can define a cell's state as the largest square ending there and then compress memory to one row.

What the Interviewer Expects
  • Define dp[i][j] as the side of the best square with bottom-right at (i, j)
  • Derive dp = 1 + min(top, left, top-left)
  • Compress to a single row with a saved diagonal
  • Return area, not side length
  • Handle empty grids
Key Topics to Cover
dynamic programming
matrix
space optimization
grid problems
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Find the largest all-healthy rectangle instead of square.
  • How would you count all healthy squares of any size?
  • Handle updates when one server flips state, without recomputing everything.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: a list of lists of 0 and 1, possibly empty. Output: the area (side squared) of the largest all-1 square....

High-Level Design

A square of side s ending at (i, j) needs squares of side at least s-1 ending at the cell above, the cell to the left, and the diagonal. So the side at (i, j) is one plus the minimum of those three, o...


Submit Your Answer
Markdown supported