Reported September 2026
Nurotwo pointers

Trapping Rain Water

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

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

With n up to 2 * 10^4, the naive scan-left-and-right-for-every-bar approach is O(n^2) and burns through 400 million operations. That's the wall Nuro's Trapping Rain Water hits, reported in September 2026. If your OA invite is sitting there, know this one cold: it's a two-pointer or prefix-max problem, and the answer is a single linear pass. The statement even hands you the formula: min(leftMax, rightMax) minus height. If you blank on the pointer movement mid-assessment, StealthCoder runs invisibly as a safety net and gives you the solution live.

The problem

You are given an integer array height of length n. n vertical bars stand on the x-axis. The i-th bar has width 1 and height height[i].
Compute how many units of water the bars can trap after rain.
Water sits above a bar only when both a strictly taller left boundary and a strictly taller right boundary exist. The water depth at index i is max(0, min(leftMax[i], rightMax[i]) - height[i]), where leftMax[i] is the tallest bar at an index < i and rightMax[i] is the tallest bar at an index > i.

Function
trap(height: int[]) → int

Examples
Example 1
height = [0,1,0,2,1,0,1,3,2,1,2,1]
return = 6
The bars trap 1 + 1 + 2 + 1 + 1 = 6 units of water.
Example 2
height = [4,2,0,3,2,5]
return = 9
The valley between the height-4 and height-5 bars traps 2 + 4 + 1 + 2 = 9 units.

Constraints
1 <= height.length <= 2 * 10^4.
0 <= height[i] <= 10^5.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that water at each index depends only on the shorter of the two boundaries. Two ways to get O(n). First, precompute leftMax and rightMax arrays, then sum max(0, min(l, r) - h). That's O(n) time and O(n) space. Second, use two pointers with running leftMax and rightMax. Move the pointer on the side with the smaller height, because that side's boundary is the limiting one, so you can finalize its water without knowing the far side exactly. Common pitfalls: moving the wrong pointer, forgetting to update the max before adding water, and adding negative values when a bar is itself the max. Heights go up to 10^5 and n up to 2 * 10^4, so the sum fits comfortably, but watch overflow in other languages. If the pointer logic slips under pressure, StealthCoder is the hedge on the live OA: it reads the problem and hands you the working code.

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

Related leaked OAs

⏵ 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 Nuro's OA.

Nuro 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

How hard is Trapping Rain Water really in the Nuro OA?+

It's a known hard-tagged problem, but the solution is short once you see it. The prefix-max version is easy to derive from the formula in the statement. The two-pointer version is the one that trips people. Get the array version working first, then optimize if time allows.

What's the trick to solving it in linear time?+

Water at index i is min(leftMax, rightMax) minus height[i]. Precompute both max arrays in two passes, or use two pointers and always advance the side with the smaller current height. The smaller side is the bottleneck, so its water is already determined.

Will brute force pass with n up to 2 * 10^4?+

Probably not. Scanning left and right for every bar is O(n^2), around 400 million steps at max input. That risks timing out on the larger hidden tests. Use prefix and suffix max arrays at minimum, which is O(n) and simple.

Is the two-pointer approach required or is the array approach fine?+

The array approach is fine. Both are O(n) time. The two-pointer one just saves O(n) memory. With n at 2 * 10^4, memory isn't a concern, so pick whichever you can write correctly without bugs.

How do I prepare for this in 48 hours?+

Code the prefix and suffix max version from scratch twice. Then write the two-pointer version once and trace it on [4,2,0,3,2,5], which should return 9. Test edge cases: length 1, strictly increasing, strictly decreasing, and all zeros. Those catch most bugs.

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

OA at Nuro?
Invisible during screen share
Get it