Practice Maximum Alternating Subsequence Sum
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices. Given an array nums, return the maximum alternating sum of any subsequence of nums (after reindexing the elements of the subsequence). A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order. For example, [2,7,4] is a subsequence of [4,2,3,7,2,1,4] (the underlined elements), while [2,4,2] is not.
Source: Maximum Alternating Subsequence Sum on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [4,2,5,3]
7
# Example 2
nums = [5,6,7,8]
8
# Example 3
nums = [6,2,1,2,4,5]
10
Constraints
Related LeetCode Problems
Practice more problems similar to Maximum Alternating Subsequence Sum.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.