Find the Largest Empty Square Block in an Excel Sheet

Last updated: November 29, 2026

Quick Overview

Given a boolean grid marking which Excel cells are empty, return the side length and top-left corner of the largest square block of empty cells, so a pasted square table will fit there.

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

0

0

0 solved


Given a boolean grid marking which Excel cells are empty, return the side length and top-left corner of the largest square block of empty cells, so a pasted square table will fit there.

A maximal-square DP grounded in Excel's paste and table placement features. Interviewers want the min-of-three-neighbors recurrence with a proof sketch, then a space optimization and the location, not just the size.

What the Interviewer Expects
  • Define dp[r][c] as the side of the largest square whose bottom-right corner is (r, c)
  • Justify dp = 1 + min(top, left, top-left)
  • Track the location of the best square
  • Use one or two rows of storage
  • Compare against the O((rc)^2) brute force
Key Topics to Cover
2D dynamic programming
maximal square
grid DP
Excel scenario
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 empty rectangle instead of a square.
  • Count all empty squares of every size.
  • The sheet is sparse with a million columns. How would you store and scan it?
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
  • sheet[r][c] is True for an empty cell.
  • Output: (side, top_row, left_col); (0, -1, -1) if no empty cell.
  • Ties: any largest square is fine....
High-Level Design

A square of side s ending at (r, c) needs squares of side s - 1 ending at the top, left and top-left neighbors. If any of those is smaller, it limits us, so `dp[r][c] = 1 + min(dp[r-1][c], dp[r][c-1],...


Submit Your Answer
Markdown supported