Skip to content

Instantly share code, notes, and snippets.

@isbo
Created October 30, 2013 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isbo/7239007 to your computer and use it in GitHub Desktop.
Save isbo/7239007 to your computer and use it in GitHub Desktop.
def fill(heights):
prev = total = 0
for i, h in enumerate(heights):
f = min(max(heights[i:]), prev)
if f > h:
total += (f - h)
prev = max(prev, h)
return total
if __name__ == "__main__":
print fill((2,5,1,2,3,4,7,7,6))
print fill((2,5,1,3,1,2,1,7,0,0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment