Trapping Water Solution Explanation

#1

I looked at the code and understand why it works but I’m really not understanding the explanation given.

Specifically this part:

When the maximum capacity is achieved, the cross-section consists of a region in which the water level is nondecreasing, followed by a region in which the water level is nonincreasing.

What is meant by water level that is nondecreasing and nonincreasing? Given the below picture from the book, how does the region to the left of the max entry have nondecreasing water level and the right region nonincreasing?

0 Likes

#2

Bump. @tsunghsienlee @adnanaziz would you mind chiming in here? Or maybe someone who understands the explanation. Still haven’t figured this out unfortunately.

0 Likes

#3

Hey @gmohammadioun,

It means when we identified the index with maximum height in the figure, in this example, it will be the one with height of 5, and its index is 7. So the water level before index 7 is nondecreasing, and the water level after 7 is nonincreasing. We will rewrite this part with example to make it clear. Let me know if you have any other problem.

0 Likes