Highest alternating integer sequence

June 27, 2023

Given a list of integer sequences like the following:

0, 1, 2, 3
4, 7, 8, 9
10, 12, 14, 15, 17

Find the integer sequence for which alternating adding and subtracting the components like below produces the highest result, which we call the highest alternating integer sequence:

n_1 + n_2 - n_3 + n_4 - n_5 + ...

Given that the results for the three above sequences are:

  1. 2
  2. 12
  3. 6

We know that the second integer sequence is the highest alternating integer sequence.

Write a function that will take an array of arrays, each containing integer sequences, and returns the index of the highest alternating integer sequence.

Some solutions can be seen here.

I would be thrilled to hear from you! Please share your thoughts and ideas with me via email.

Back to Index