A valid tail-sequence of an array meets the following criteria:
As an example, for array, [1, 2, 3, 4], the valid tail-sequences are:
[1, 2], [1, 2, 3], [2, 3, 4], [3, 4]
Implement a function, aggregateMaxTailSequenceSums(), which:
Example 1:
Input: [-2, 3, -1, 2, 0]
Output: 10
Explanation: using tail-sequences [-2, 3] => 1, [-2, 3, -1, 2] => 2, [3, -1, 2, 0] => 4, [-1, 2, 0] => 1, [2, 0] => 2
1 + 2 + 4 + 1 + 2 = 10Example 2:
Input: [1, -6, 2, -7, 4, -4]
Output: 0
Explanation: using tail-sequence [4, -4]Example 3:
Input: [-1, -2, -4, 1]
Output: -3
Explanation: using either tail-sequence [-1, -2] or [-4, 1]