Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
merge intervals solution in Clear category for Painting Wall by flpo
def merge_intervals(intervals):
new = [intervals[0]]
for a, b in intervals[1:]:
if a > new[-1][1] + 1:
new.append([a, b])
new[-1][1] = max(b, new[-1][1])
return new
def checkio(length, intervals):
return next((i for i in range(1, len(intervals) + 1)
if sum(y - x + 1 for x, y in merge_intervals(sorted(intervals[:i]))) >= length), -1)
Aug. 6, 2017