Here’s a list of integer arrays:
0, 1, 2, 3
4, 7, 8, 9
10, 12, 14, 15, 17
Calculate the result of the following calculation for each array in this list: start with the left-most value. Take turns adding and subtracting the next value from this value. Continue until you reach the end of the array. As a sum formula, it looks like this:
n_1 + n_2 + (- n_3) + n_4 + (- n_5) + ...
The three arrays from the list look like this after running this calculation:
Sequence | Result |
---|---|
0, 1, 2, 3 | 2 |
4, 7, 8, 9 | 12 |
10, 12, 14, 15, 17 | 6 |
Now, find the index of the largest result. I call this the highest alternating integer sequence.
In the table, you can see that the second integer sequence is the highest alternating integer sequence. Thus, the index is 1.
Write a function that takes a list of integer arrays and returns the index of the highest alternating integer sequence.