Trapping Rain Water
Recognize the pattern
Brute force idea
If you approach Trapping Rain Water in the most literal way possible, you get this: For each position, find the max height to its left and right. Re-scans the array for every position. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.
Better approach
A calmer way to see Trapping Rain Water is this: Two pointers from both ends converging inward. Water at any position = min(maxLeft, maxRight) - height. Move the pointer with the smaller max — you know the water level is bounded by the smaller side. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.
Key invariant
The truth you want to protect throughout Trapping Rain Water is this: Water at position i = min(maxLeft, maxRight) - height[i]. If maxLeft < maxRight, the water level at the left pointer is determined by maxLeft regardless of what's further right — so you can safely compute it and move inward. If that remains true after every update, the rest of the reasoning has a stable place to stand.
Watch out for
The trap in Trapping Rain Water usually looks like this: Not understanding WHY you move the smaller side — if maxLeft < maxRight, no bar to the right can make the left pointer's water level higher. It's bounded by maxLeft, period. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.