Trapping Rain Water II
Updated
Problem statement
You are given an m x n integer matrix heightMap, where each value is the height of one unit-width cell in a two-dimensional terrain.
After rain falls, water can remain above a cell only when surrounding terrain prevents it from flowing to the outer boundary.
Return the total volume of trapped water.
Function
trapRainWater(heightMap: int[][]) → intExamples
Example 1
heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]return = 4The boundary-driven water level traps four units across the two interior low regions.
Example 2
heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]return = 10The boundary height is three. The eight height-two cells hold one unit each, and the center holds two.
Example 3
heightMap = [[1,1,1],[1,0,1],[1,1,1]]return = 1The center cell is enclosed by height-one boundary cells.
Constraints
1 <= m, n <= 200.m * n <= 40000.0 <= heightMap[i][j] <= 20000.
More Bloomberg LP Phone Screen questions
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Find the Safest Path in a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Swim in Rising WaterUiPath · PHONE SCREEN
- Shortest Distance from All BuildingsWaymo · PHONE SCREENWaymo interview questions
- Maximum-Clearance Path From a PointGoogle · PHONE SCREENGoogle interview questions
- 8-Puzzle SolverAirbnb · PHONE SCREENAirbnb interview questions
- Matrix EscapeByteDance · PHONE SCREENByteDance interview questions
- Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
- Reachable Exits in an Obstacle GridWhatNot · PHONE SCREENWhatNot interview questions
- Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
- Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)