Sign In
You are coding as a Guest. Sign in with your RoleNest account to permanently track your streak, earn XP, and climb the Campus Leaderboard!
Sign In with RoleNest
🔥Trapping Rain Water: Monotonic Elevation TrapHard
SUPER HARD PROBLEM OF THE DAY+150 XP • FAANG OA TIER

High-difficulty challenge matching authentic Google, Amazon & Uber L5 online assessment conditions.

HardTwo Pointers•Acceptance: 61.2%

Trapping Rain Water: Monotonic Elevation Trap

Targeted in FAANG & Tech OA:GoogleAmazonMicrosoft
Real-World Engineering Context
Applied in GIS topographical hydrology modelling and reservoir watershed simulations at Google Maps and Earth Engine to calculate surface water runoff retention.
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. Water can only be trapped between two higher boundaries. The trapped water at any index is `min(maxLeft, maxRight) - height[i]`.

Sample Test Cases

Input: [[0,1,0,2,1,0,1,3,2,1,2,1]]
Expected: 6
Input: [[4,2,0,3,2,5]]
Expected: 9
Input: [[3,3,3,3]]
Expected: 0

Constraints

  • n == height.length
  • 1 <= n <= 2 * 10^4
  • 0 <= height[i] <= 10^5
Recruiter Fast-Track ReferralVerified Candidate
Direct pipeline to Google, Amazon, Microsoft, Swiggy, & Uber recruiters
DevScore: 750/1000

Top DevScore profiles bypass resume screening filters. Every verified problem solve writes authentic proof-of-work to your profile and dispatches you directly into employer inboxes on RoleNest.