Python
Using the integers from the problem statement, define seqs
:
seqs = [
[0, 1, 2, 3],
[4, 7, 8, 9],
[10, 12, 14, 15, 17],
]
You can use the following method hais(seqs)
to calculate the result:
def hais(seqs):
results = [0] * len(seqs)
for ix, seq in enumerate(seqs):
result = seq[0]
add = True
for i in seq[1:]:
if add:
result += i
else:
result -= i
add = not add
results[ix] = result
return results.index(max(results))
This is a sample run for the seqs
array:
>>> hais(seqs)
1