Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Painting Wall solution in Uncategorized category for Painting Wall by capback250
def checkio(length, actions):
for x in range(1, len(actions)+1):
if length <= compress(actions[:x]):
return x
return -1
def compress(args):
nargs = sorted(args, key=lambda x:x[0])
for i in range(len(nargs)-1):
if nargs[i+1][0] <= nargs[i][1]:
nargs[i+1] = [nargs[i][0], max(nargs[i][1], nargs[i+1][1])]
nargs[i] = []
return sum([int(x[1]) - int(x[0]) + 1 for x in filter(bool, nargs)])
Feb. 12, 2016