Trains the technique from
LeetCode 407Trapping Rain Water IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A tray is moulded from square cells whose wall heights are given as heightMap. Water is poured over the whole tray until it settles.
Water spreads between cells that share a side, and any water reaching the outside edge of the tray runs off. A cell holds water up to the level the surrounding walls can keep in, and never below its own height.
Return the total volume of water the tray holds once everything has settled.
Example 1
Walls of 9 surround the tray, so the six inner cells fill to level 9, and the volume is what is left above each of their own heights.
Example 2
The single inner cell stands taller than the wall around it, so nothing collects.
Example 3
A tray one cell across has no inside at all, so nothing can be held.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def trap_rain_water(heightMap: list[list[int]]) -> int:public int trapRainWater(int[][] heightMap)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.