Trapping Rain Water
Updated
Problem statement
You are given n non-negative integers representing an elevation map. Each bar has width 1.
Return how many units of rain water the elevation map can trap.
Function
trap(height: int[]) → intExamples
Example 1
height = [0,1,0,2,1,0,1,3,2,1,2,1]return = 6The bars trap a total of 6 units of water.
Example 2
height = [4,2,0,3,2,5]return = 9The elevation map traps 9 units in total.
Example 3
height = [1,2,3]return = 0A strictly increasing elevation map cannot trap water.
Constraints
1 <= height.length <= 20000.0 <= height[i] <= 100000.
More Google Online Assessment questions
- Minimum Operations to Make a SubsequenceOA · Seen Nov 2026
- Book Reading EveningsOA · Seen Nov 2026
- Count Score CategoriesOA · Seen Nov 2026
- Minimum Cars for Rental RequestsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Shortest Path in a Binary MatrixOA · Seen Nov 2026
- Robot Assembly Line ConflictsOA · Seen Oct 2026
- Assign LockerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Biggest Number From DigitsOA · Seen Oct 2026
- Consolidate On-Call RotationsOA · PHONE SCREEN · Seen Oct 2026
- Decreasing SubsequencesOA · Seen Sep 2026
Similar questions at other companies
- Trapping Rain WaterMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Rain Kept Between WallsDocuSign · PHONE SCREENDocuSign interview questions
- Rain Water Held Between BarsAdobe · PHONE SCREENAdobe interview questions
- Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
- Alternating Jumps to the Last IndexExpedia · OAExpedia interview questions
- Trapping Rain WaterTeradata · ONSITE INTERVIEW
- Trapping Rain WaterBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Trapping Rain WaterOracle · PHONE SCREENOracle interview questions
- Trapping Rain WaterAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Trapping Rain WaterKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions