Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Painting Wall by natsuki
def checkio(num, data):
# Make segments
# ex.
# data = [[1, 5], [11, 15], [2, 14], [21, 25]]
# segments = [(1, 1), (2, 5), (6, 10), (11, 14), (15, 15), (16, 20), (21, 25)]
numbers = sorted([n for start, end in data for n in (start, end + 1)])
segments = [(n1, n2 - 1) for n1, n2 in zip(numbers[:-1], numbers[1:])]
painted = set()
for i, (start, end) in enumerate(data):
painted |= {(s, e) for s, e in segments if start <= s and e <= end}
if sum([e - s + 1 for s, e in painted]) >= num:
return i + 1
return -1
April 18, 2014
Comments: