Skip to content

Instantly share code, notes, and snippets.

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