Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
dynamic solution in Clear category for Stair Steps by Oleg_Babaev
def checkio(stairs):
steps = [max(stairs[0],stairs[1])] + [0]*(len(stairs)-1)
for i in range(len(stairs)):
steps[i] = stairs[i] + max(steps[i-1],steps[i-2])
return max(steps[len(stairs)-2],steps[len(stairs)-1])
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio([5, -3, -1, 2]) == 6, 'Fifth'
assert checkio([5, 6, -10, -7, 4]) == 8, 'First'
assert checkio([-11, 69, 77, -51, 23, 67, 35, 27, -25, 95]) == 393, 'Second'
assert checkio([-21, -23, -69, -67, 1, 41, 97, 49, 27]) == 125, 'Third'
print('All ok')
Dec. 27, 2020
Comments: