Coding

Calculate how much rainwater can be trapped between elevation bars.

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.

Input: height = [4,2,0,3,2,5]

Output: 9

Explanation: Water is trapped between the boundaries of 4 and 5. The trapped volumes at indices 1 through 4 are 2, 4, 1, and 2 respectively.

Was asked at

Practice this question with AI

First session is free - no credit card required.

Go Premium

More interviews, more skills, more success.

No answers yet

Be the first to share your approach to this question

Practice More Questions