Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

Boss fightThe Tempest Cistern

Learn
Play
Prove
Lesson 1 of 5

Live algorithm trace

Trapping rain with two sentinels

Complete execution
1 of 12

Initialize both boundaries and both running maxima.

1left = 0; right = length - 1
2leftMax = rightMax = water = 0
3resolve the side with the shorter current wall
4update that side's maximum
5add maximum - current height; move inward
6return water
leftMax = 0rightMax = 0water = 0

The final storm has arrived. Between these walls, rain collects wherever a shorter column is bounded by taller walls on both sides. Measure every trapped unit.

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead