Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
merge and summ solution in Clear category for Painting Wall by kdim
def sumranges(ranges): # merge and return summ of
ranges = sorted(ranges) # merged intervals
r = [ranges[0]] #
for i in ranges[1:]:
a, b, x, y = (*r[-1], *i)
r = r[:-1] + ([(a, b), (x, y)] if x > b else [(a, max(b,y))])
return sum(b - a + 1 for a, b in r)
def checkio(required, operations):
for i in range(1, len(operations) + 1): # in turn pass intervals
if required <= sumranges(operations[:i]): # if summ >= then return number of intervals
return i #
return -1
Feb. 4, 2021
Comments: