Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First, by recursion solution in Clear category for Painting Wall by Tinus_Trotyl
def checkio(required, operations):
def merge(intervals):
if len(intervals)== 1: return intervals
vs, ve, ws, we = *intervals[0], *intervals[1]
if vs <= ws <= ve + 1: return merge([[min(vs, ws), max(ve, we)], *intervals[2:]])
return [intervals[0], *merge(intervals[1:])]
for n in range(1, len(operations) + 1):
if sum(paint[1] - paint[0] + 1 for paint in merge(sorted(operations[:n]))) >= required: return n
return -1
Aug. 4, 2019