| 1 | Start | - | [] | 0 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 2 | Push current index | 0 | [0] | 0 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 3 | Push current index | 1 | [0,1] | 0 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 4 | Push current index | 2 | [0,1,2] | 0 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 5 | Pop top (2) since height[2]=0 < height[3]=2 | 3 | [0,1] | 0 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 6 | Calculate trapped water: distance=3-1-1=1, bounded_height=min(2,1)-0=1 | 3 | [0,1] | 1 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 7 | Add water: 1 | 3 | [0,1] | 1 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 8 | Pop top (1) since height[1]=1 < height[3]=2 | 3 | [0] | 1 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 9 | Calculate trapped water: distance=3-0-1=2, bounded_height=min(2,0)-1=-1 (ignore) | 3 | [0] | 1 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 10 | Push current index | 3 | [0,3] | 1 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 11 | Push current index | 4 | [0,3,4] | 1 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 12 | Push current index | 5 | [0,3,4,5] | 1 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 13 | Pop top (5) since height[5]=0 < height[6]=1 | 6 | [0,3,4] | 1 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 14 | Calculate trapped water: distance=6-4-1=1, bounded_height=min(1,1)-0=1 | 6 | [0,3,4] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 15 | Add water: total=2 | 6 | [0,3,4] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 16 | Push current index | 6 | [0,3,4,6] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 17 | Pop top (6) since height[6]=1 < height[7]=3 | 7 | [0,3,4] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 18 | Calculate trapped water: distance=7-4-1=2, bounded_height=min(3,1)-1=0 | 7 | [0,3,4] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 19 | Pop top (4) since height[4]=1 < height[7]=3 | 7 | [0,3] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 20 | Calculate trapped water: distance=7-0-1=6, bounded_height=min(3,0)-1=-1 (ignore) | 7 | [0,3] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 21 | Push current index | 7 | [0,3,7] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 22 | Push current index | 8 | [0,3,7,8] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 23 | Push current index | 9 | [0,3,7,8,9] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 24 | Pop top (9) since height[9]=1 < height[10]=2 | 10 | [0,3,7,8] | 2 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 25 | Calculate trapped water: distance=10-8-1=1, bounded_height=min(2,2)-1=1 | 10 | [0,3,7,8] | 3 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 26 | Add water: total=3 | 10 | [0,3,7,8] | 3 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 27 | Push current index | 10 | [0,3,7,8,10] | 3 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 28 | Push current index | 11 | [0,3,7,8,10,11] | 3 | [0,1,0,2,1,0,1,3,2,1,2,1] |
| 29 | End of array reached | - | [0,3,7,8,10,11] | 3 | [0,1,0,2,1,0,1,3,2,1,2,1] |