Reported July 2026
Rupeektwo pointers

Trapping Rain Water

Reported by candidates from Rupeek's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Rupeek OA. Under 2s to a working solution.
Founder's read

Trapping Rain Water at Rupeek, reported July 2026, boils down to one question: how high can the water stand over each bar? That's min(tallest bar to the left, tallest bar to the right) minus the bar's own height. Sum that across the array and you're done. It's a classic two-pointers problem, and the brute force is easy to write and too slow. If you've got the OA in the next day or two, learn the shape of the answer now. StealthCoder sits invisibly on your screen during the live assessment as a safety net if your mind goes blank on the pointer logic.

The problem

Given non-negative bar heights where every bar has width 1, return the total amount of rain water trapped between the bars.

Function
trap(height: int[]) → int

Examples
Example 1
height = [0,1,0,2,1,0,1,3,2,1,2,1]
return = 6
Example 2
height = [4,2,0,3,2,5]
return = 9

Reported by candidates. Source: FastPrep

Pattern and pitfall

Every bar holds water equal to min(maxLeft, maxRight) minus height, floored at zero. The naive version rescans both sides for each bar and runs O(n^2). The clean fix is two pointers, left and right, with leftMax and rightMax. Move whichever side has the smaller current height. If height[left] is below leftMax, add leftMax minus height[left], otherwise update leftMax. The smaller side is the bottleneck, so the other side can't change its answer. That gives O(n) time and O(1) space. A prefix-max and suffix-max array also works at O(n) space, and it's easier to get right under pressure. Common pitfalls: adding negative water, moving the wrong pointer, and forgetting empty or short arrays. If you freeze mid-OA, StealthCoder can hand you the pointer template so you can verify it against both examples (6 and 9).

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Trapping Rain Water cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder
⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as trapping rain water. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Rupeek's OA.

Rupeek reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Trapping Rain Water FAQ

What's the trick to Trapping Rain Water?+

Water over a bar equals min(tallest left, tallest right) minus its height. Everything else is just computing those two maxima efficiently. Precompute them in arrays, or use two pointers and track running maxima from each end, moving the side with the smaller height.

How hard is this problem really?+

It's labeled hard, but the idea is short once you see the per-bar formula. The difficulty is knowing which pointer to move. If you can write the prefix/suffix max version first, you already have a correct, accepted answer.

Should I use two pointers or prefix/suffix arrays?+

Prefix and suffix arrays are simpler and harder to break, using O(n) extra space. Two pointers use O(1) space and impress more, but they're easier to mess up. In an OA where correctness is what counts, pick the one you can write without hesitation.

Is this pattern still asked in 2026?+

Yes. Rupeek's report is from July 2026, and this problem is a long-running staple. Array scans with running maxima and two pointers keep showing up in assessments because they test whether you can reduce a picture to a formula.

How do I prepare in 48 hours?+

Write the brute force, then the prefix/suffix version, then the two-pointer version, from memory. Test on [0,1,0,2,1,0,1,3,2,1,2,1] expecting 6 and [4,2,0,3,2,5] expecting 9. Then try edge cases: empty array, one bar, strictly increasing heights.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Rupeek.

OA at Rupeek?
Invisible during screen share
Get it