The question is similar to here, besides:
- We are looking for the maximum.
- The answer can contain the first or last element of the array (but not both - because we consider them as adjacent).
My attempt:
I think of using the same idea of RomCoo in the link above, but adjust it to this problem:
- Find the largest number.
- Find the second largest that is not a neighbour of the first. Then build the sum.
- Calculate the sum of both neighbours of the first number. Check if its larger then the first sum. If not: take the first sum, otherwise take the second one.
I believe that the pairs on steps (2) and (3) are the only ones who can make the largest sum, but I can't formally prove it.
If this correct how can you formally prove it?
And if not, how do you solve it?