Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
First, check if finalSum is divisible by 2. If it isn’t, then we cannot split it into even integers.
Let k be the number of elements in our split. As we want the maximum number of elements, we should try to use the first k - 1 even elements to grow our sum as slowly as possible.
Thus, we find the maximum sum of the first k - 1 even elements which is less than finalSum.
We then add the difference over to the kth element.