Choose a nonempty subsequence of nums, preserving relative order. Its alternating sum adds the first chosen value, subtracts the second, adds the third, and continues alternating. Return the greatest possible alternating sum. Positions are numbered within the chosen subsequence, not the original array.
Example 1:
Input: nums = [9,1,9]
Output: 17Explanation: Choose all three values: 9 - 1 + 9 = 17. This is larger than the alternating sum of any shorter subsequence.
Example 2:
Input: nums = [1,2,3]
Output: 3Explanation: Choose the single value 3, giving sum 3. Choosing all entries gives only 1 - 2 + 3 = 2.
Example 3:
Input: nums = [4,4]
Output: 4Explanation: Choose either one of the two 4s to get 4. Choosing both would give 4 - 4 = 0.
Constraints:
1 <= nums.length <= 1000001 <= nums[i] <= 100000