Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Flood Area by Moff
def flood_area(diagram):
heights = [0]
for c in diagram:
heights.append(heights[-1] + '\\_/'.find(c) - 1)
result = []
a = 0
while a < len(heights) - 1:
if heights[a] > heights[a + 1]:
try:
b = heights.index(heights[a], a + 1)
result.append((b - a) * heights[a] - sum(heights[a:b]))
a = b
continue
except ValueError:
pass
a += 1
return result
April 8, 2019