Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Stair Steps by mangeurdecowan
def checkio(numbers):
result, negs, temp = 0, [], []
while numbers:
num = numbers.pop(0)
if num >= 0:
result += num
if temp != []:
negs.append(temp)
temp = []
else:
temp.append(num)
if temp != []: negs.append(temp)
for neg in negs:
if len(neg) == 1:
continue
elif len(neg) == 2:
result += max(neg)
else:
candidates, temp = [], [[neg.pop(0)], [0]]
while neg:
num = neg.pop(0)
candidates, temp = temp, []
while candidates:
candidate = candidates.pop(0)
temp.append(candidate + [num])
if candidate[-1] != 0:
temp.append(candidate + [0])
result += max([sum(x) for x in temp])
return result
Sept. 23, 2021
Comments: