Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
7-liner: guessing accumulate idea solution in Creative category for Flood Area by przemyslaw.daniel
def flood_area(data):
merger = lambda p, q: p[:-3]+(p[-3]+q[0], p[-2], p[-1]) if p[-2] < q[1] < p[-1] else p+q
result, stack, acc = [], [], __import__('itertools').accumulate
for i, char in enumerate(data):
stack += [i]*(char == '\\')
result += [(i-stack[-1], stack.pop(), i)] if stack and char == '/' else []
return list(acc(result[::-1], merger))[-1][::3][::-1] if result else ()
March 11, 2019
Comments: