Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Flood Area by Tinus_Trotyl
def flood_area(diagram):
def fill(x):
depth, flood = 0, 0
while diagram[x:]:
depth += {'\\':1, '/':-1, '_':0}[diagram[x]]
flood += depth
if depth == 0:
return x, [flood] if flood else []
x += 1
return x, []
x, floods = 0, []
while diagram[x:]:
if diagram[x] == '\\':
y, flood = fill(x)
floods += flood
if flood: x = y
x += 1
return floods
June 25, 2019
Comments: