HARDasked at 81 companies

Trapping Rain Water

A hard-tier problem at 65% community acceptance, tagged with Array, Two Pointers, Dynamic Programming. Reported in interviews at Coveo and 80 others.

Founder's read

Trapping Rain Water is the hard-label problem that separates candidates who can think spatially from those who brute-force. It's asked by 81 companies including Goldman Sachs, Intel, ServiceNow, and Flipkart, and has a 65% acceptance rate, which sounds high until you're on the clock and realize the naive approach times out. You're given an elevation map as an array of heights. The problem: how much water gets trapped between the bars after it rains. The catch is that a single pass or greedy attempt will miss trapped water entirely. If you hit this live and blank on the two-pointer or monotonic stack trick, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
81
Difficulty
HARD
Acceptance
65%

Companies that ask "Trapping Rain Water"

If this hits your live OA

Trapping Rain Water is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.

Get StealthCoder
What this means

The insight: water trapped at any position depends on the max height to its left and max height to its right. If you precompute both in O(n) space, you solve it in linear time. The trap at index i is min(leftMax, rightMax) minus the height at i. Two pointers is faster in space: walk inward from both ends, track the running max on each side, and greedily fill from the shorter end because the taller end guarantees the height ceiling. Stack-based monotonic approach also works but is harder to code under pressure. Most candidates fail because they try greedy single-pass without precomputation, or they compute max correctly but mess up the subtraction logic. When you're live and the problem hits, the pattern is a class-A pattern, but the pressure kills it. StealthCoder hedges that moment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Trapping Rain Water recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Trapping Rain Water interview FAQ

Why is the naive greedy approach wrong?+

Greedy single-pass can't know future heights, so it can't compute the bounding height for water. Example: heights [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]. At index 1, you don't know index 3 is taller until you've passed it. You need precomputed max heights or two pointers walking inward.

Is this still asked at FAANG and tier-1?+

Frequently. The input shows 81 total company reports, including Goldman Sachs, Intel, ServiceNow, and Flipkart. Hard-label classic patterns stay in rotation because they filter for spatial reasoning and optimization thinking, both critical for system design later.

What's the time and space tradeoff?+

Precompute leftMax and rightMax arrays: O(n) time, O(n) space, clean code. Two-pointer inbound: O(n) time, O(1) space, slightly harder to reason about. Monotonic stack: O(n) time, O(n) space, most complex. All three pass, but two-pointer is the interview sweet spot.

How does this relate to monotonic structures?+

Monotonic stack approach: maintain a decreasing stack of indices, pop when you see a taller bar. For each pop, water is trapped between the popped bar and current bar, bounded by the smaller of the two walls. It's the same water calculation, different traversal order. Stack is overkill unless explicitly asked.

What's the most common failure mode?+

Off-by-one in the loop bounds, or forgetting that water = min(leftMax, rightMax) minus height[i], not just the max difference. Candidates also sometimes compute max arrays but forget to update them as they iterate. Test your precomputation logic on [0, 1, 0, 2] before submitting.

Want the actual problem statement? View "Trapping Rain Water" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.