Trap the Rainwater

Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.

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.

Talk this problem through with an AI coach

This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.

Start free →