Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Flood Area by zongareight
from typing import Iterable
def flood_area(diagram: str) -> Iterable[int]:
slopes, floods = [], []
for i, ch in enumerate(diagram):
if ch == "\\":
slopes.append(i)
elif ch == "/" and slopes:
k = slopes.pop()
flood = i - k
floods.append((k, flood))
while len(floods) > 1 and k < floods[-2][0]:
floods.append((k, floods.pop()[1] + floods.pop()[1]))
return [flood for _, flood in floods]
Oct. 27, 2022