Tap here to switch tabs
Problem
Submissions

Problem: Maximum Alternating Subsequence Sum

Try to solve the Maximum Alternating Subsequence Sum problem.

Statement

The alternating sum of an array indexed from 00 is defined as the sum of the elements at even indices minus the sum of the elements at odd indices.

For instance, the alternating sum of an array [a0,a1,a2,a3][a_0, a_1, a_2, a_3] equals (a0+a2)−(a1+a3)(a_0 + a_2) - (a_1 + a_3).

Given an integer array nums, return the maximum possible alternating sum of any subsequence of nums after indexing the chosen subsequence starting from 00.

A subsequence of an array is a sequence obtained by deleting some (possibly zero) elements from the original array without altering the relative order of the remaining elements.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Alternating Subsequence Sum

Try to solve the Maximum Alternating Subsequence Sum problem.

Statement

The alternating sum of an array indexed from 00 is defined as the sum of the elements at even indices minus the sum of the elements at odd indices.

For instance, the alternating sum of an array [a0,a1,a2,a3][a_0, a_1, a_2, a_3] equals (a0+a2)−(a1+a3)(a_0 + a_2) - (a_1 + a_3).

Given an integer array nums, return the maximum possible alternating sum of any subsequence of nums after indexing the chosen subsequence starting from 00.

A subsequence of an array is a sequence obtained by deleting some (possibly zero) elements from the original array without altering the relative order of the remaining elements.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5