Skip to interview prep
Apexed
Problem list110 / 125

110. Trapping Rain Water

HardTwo pointers

height describes an elevation map where each bar has width 1. Return how much rain water is trapped between the bars.

Example 1

Input: height = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]
Output: 6

Constraints

  • 1 ≤ height.length ≤ 2 × 10⁴

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Trapping Rain Water — coding interview practice — Apexed