Trapping Rain Water
Updated
Problem statement
Each nonnegative integer in height is the height of a unit-width bar. Return the total water trapped between the bars after rain.
Water above a bar is limited by the shorter of the tallest bars on its left and right, including that bar itself.
Function
trap(height: int[]) → intExamples
Example 1
height = [0,1,0,2,1,0,1,3,2,1,2,1]return = 6The trapped depths at indices 2, 4, 5, 6, 9, and 10 are 1, 1, 2, 1, 1, and 0. Their sum is 6.
Example 2
height = [4,2,0,3,2,5]return = 9The interior depths are 2, 4, 1, and 2, for a total of 9.
Constraints
- 0 <= height.length <= 20000
- 0 <= height[i] <= 100000
More Citadel Phone Screen questions
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
- Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
- Top Ten Trades by Notional ValuePHONE SCREEN · Seen Sep 2026
- Exchange BBO and Market-Wide NBBOPHONE SCREEN · Seen Sep 2026
- Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Subarray Product Less Than KApple · PHONE SCREENApple interview questions
- 3SumAmazon · PHONE SCREEN
- Subarray Product Less Than KAngel One · PHONE SCREEN
- Subarray Product Less Than KThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Trapping Rain WaterGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
- Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Find All Pythagorean TripletsDell Technologies · PHONE SCREENDell Technologies interview questions
- Meeting Rooms IIUber · PHONE SCREENUber interview questions
- Sort a Quadratic-Transformed ArrayLinkedIn · PHONE SCREENLinkedIn interview questions