Largest Square Solar Panel Site on a Rooftop Suitability Grid

Last updated: November 29, 2026

Quick Overview

Given an m x n binary grid from a Project Sunroof style rooftop scan where 1 means a cell is suitable for panels, return the area of the largest all-ones square.

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

0

0

0 solved


Given an m x n binary grid from a Project Sunroof style rooftop scan where 1 means a cell is suitable for panels, return the area of the largest all-ones square.

A Google screen DP problem grounded in rooftop solar analysis. The interviewer wants the recurrence that a square ending at a cell is limited by its three neighbors, a clear argument for it, and a space optimization to one row.

What the Interviewer Expects
  • Defines dp[r][c] as the side of the largest square with bottom-right corner at (r, c)
  • Explains the min of top, left and top-left plus one
  • Returns side squared as the area
  • Reduces space to O(n) with a rolling row and a saved diagonal
  • Handles all-zero and single-row grids
Key Topics to Cover
Dynamic Programming
Rolling Arrays
Binary Grids
Recurrence Proof
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
  • Count all all-ones squares of every size, not just the largest.
  • Return the largest all-ones rectangle instead of a square.
  • Allow up to one unsuitable cell inside the square.
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: grid of 0/1 ints (or '0'/'1' chars, normalize first).
  • Output: area of the largest axis-aligned square of 1s, 0 if none....
High-Level Design

Let side(r, c) be the largest square whose bottom-right corner is (r, c). If the cell is 0, it is 0. Otherwise it is 1 + min(side above, side left, side up-left): the square can only extend as f...


Submit Your Answer
Markdown supported