Count City Cells Inside At Least K Overlapping Surge Zones
Last updated: November 29, 2026
Quick Overview
A city is an R x C grid of cells. Given a list of surge zones as inclusive rectangles (r1, c1, r2, c2), return how many cells are covered by at least k zones.
Uber
November 29, 20260
0
0 solved
A city is an R x C grid of cells. Given a list of surge zones as inclusive rectangles (r1, c1, r2, c2), return how many cells are covered by at least k zones.
A grid problem in the style of Uber's technical screens, set in surge pricing where zones overlap. The interviewer looks for a 2D difference array so each rectangle costs O(1) to add, instead of painting every cell.
What the Interviewer Expects
- Explains why painting each rectangle is O(Z * R * C)
- Uses four corner updates per rectangle
- Rebuilds coverage with a 2D prefix sum
- Counts cells meeting the threshold
- Handles inclusive bounds with a padded array
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 answer many queries for different k values?
- What if the city is huge and sparse, say 10^9 by 10^9 coordinates?
- How would you find the single most-covered 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: R, C, list of rectangles with 0 <= r1 <= r2 < R and 0 <= c1 <= c2 < C, and k >= 1. Output: number of cells with coverage at least k. Zones may number in the hundreds of thousands, so ...
High-Level Design
In a 2D difference array d, adding 1 over a rectangle is d[r1][c1] += 1, d[r1][c2+1] -= 1, d[r2+1][c1] -= 1, d[r2+1][c2+1] += 1. A 2D prefix sum then gives each cell's coverage: `cov[r][c] =...