← Practice · Two pointers
Trapping Rain Water Hard
Given an array of non-negative integers representing an elevation map where each bar has width 1, compute how much rain water it can trap.
Examples
[0,1,0,2,1,0,1,3,2,1,2,1] -> 6[4,2,0,3,2,5] -> 9
Define a function named trap in JavaScript.
00:00
JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests