FastPrepTrapping Rain Water

Trapping Rain Water

Rupeek logoRupeek● HardONSITE 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
See Rupeek hiring insights
Saved
public int trap(int[] height) {
  // write your code here
}
Checking account…