Problem · Array

Trapping Rain Water

Learn this problem
HardRupeekONSITE INTERVIEW

Problem statement

Given non-negative bar heights where every bar has width 1, return the total amount of rain water trapped between the bars.

Function

trap(height: int[]) → int

Examples

Example 1

height = [0,1,0,2,1,0,1,3,2,1,2,1]return = 6

Example 2

height = [4,2,0,3,2,5]return = 9
drafts saved locally
public int trap(int[] height) {
  // write your code here
}
height[0,1,0,2,1,0,1,3,2,1,2,1]
expected6
checking account