Skip to content

Instantly share code, notes, and snippets.

joneschris

Block or report user

Report or block joneschris

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:8049901
heights = [2, 5, 1, 2, 3, 4, 7, 7, 6]
totalWater = 0
for index in range(0, len(heights)):
currentHeight = heights[index]
maxLeftHeight = max(heights[:index]) if index > 0 else 0
maxRightHeight = max(heights[index:])
smallestMaxHeight = min(maxLeftHeight, maxRightHeight)
water = smallestMaxHeight - currentHeight if smallestMaxHeight - currentHeight > 0 else 0
You can’t perform that action at this time.