Water Pooled on a 2D Height Map of a Data Center Roof
Last updated: November 29, 2026
Quick Overview
Given a 2D grid of roof heights, return how many units of rainwater stay pooled after rain, where water can drain off any edge cell.
Meta
November 29, 20260
0
0 solved
Given a 2D grid of roof heights, return how many units of rainwater stay pooled after rain, where water can drain off any edge cell.
A hard Meta onsite question that extends the familiar 1D trapping problem to two dimensions, framed as data center roof drainage. The interviewer is looking for the boundary-inward priority-queue sweep and a convincing reason why the lowest boundary cell decides each neighbor's water level.
What the Interviewer Expects
- Explain why the 1D two-pointer method does not extend directly
- Seed a min-heap with all boundary cells
- Always expand from the lowest boundary cell
- Raise each newly visited cell's effective height to the current level
- Analyze O(mn log(mn))
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
- What if some interior cells are drains?
- How would you report the volume per separate pool?
- Can you do it with a bucket queue when heights are small integers?
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: m by n grid of non-negative heights.
- Water escapes through any edge cell.
- Output: total trapped units (sum over cells of water depth)....
High-Level Design
Water above a cell can rise only to the lowest point on the wall surrounding it, where the wall is the path to the edge with the smallest maximum height.
Sweep inward from the edge, like Dijkstra...