Skip to content

Instantly share code, notes, and snippets.

@joneschris joneschris/gist:8049901
Last active Dec 31, 2015

Embed
What would you like to do?
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
print("{}{}".format("X" * currentHeight, "w" * water))
totalWater = totalWater + water
print("Total Water: {}".format(totalWater))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.