Count All Square Service Zones in a Coverage Grid
Last updated: November 29, 2026
Quick Overview
A coverage grid marks cells with 1 where Uber has active driver supply. Count every square sub-grid (of any size) made entirely of 1s, which the ops team uses to measure how many square service zones could be launched.
Uber
November 29, 20260
0
0 solved
A coverage grid marks cells with 1 where Uber has active driver supply. Count every square sub-grid (of any size) made entirely of 1s, which the ops team uses to measure how many square service zones could be launched.
An Online Assessment style dynamic programming problem on a grid, framed around Uber's city expansion and coverage maps. The grader wants the insight that the largest square ending at a cell also counts every smaller square ending there.
What the Interviewer Expects
- Defines dp[r][c] as the largest all-ones square with bottom-right at (r, c)
- Uses min of top, left and top-left plus one
- Sums dp values to count all squares
- Handles first row and first column
- Notes the O(C) space optimization
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return only the side length of the largest square?
- How would you count rectangles instead of squares?
- How would you handle a grid that is updated cell by cell?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of lists of 0/1, up to 300 x 300. Output: number of all-ones square sub-grids. Enumerating every square and checking it is far too slow....
High-Level Design
Let dp[r][c] be the side of the largest all-ones square whose bottom-right corner is (r, c). If the cell is 1, dp[r][c] = 1 + min(top, left, top-left), because a square of side s at this corner ...