Trap the Rainwater
Talk it through out loud with your AI coach.
The problem
- hard
- Pro
Given a row of bars of different heights, work out how much rainwater would be trapped between them after it rains. Explain a linear-time approach and how to get it down to constant extra memory.
What a strong answer covers
- What decides how much water sits above any single bar.
- A linear approach that precomputes information from both sides.
- How to keep the same idea with constant extra memory, and why it's safe.
- The final cost and small edge cases.
Common mistake: Looking only at the immediate neighbours of a bar instead of the tallest bars on each side.
Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.
Practise it out loud