Tap here to switch tabs
Problem
Submissions

Problem: Maximum Alternating Subarray Sum

Maximum Alternating Subarray Sum asks you to find the largest alternating sum of any nonempty subarray in an array, with signs starting positive and switching at each element. Values may be negative.

Statement

Given an array of integers nums, determine the maximum alternating subarray sum among all non empty subarrays of nums.

The alternating sum of a subarray starting at index i and ending at index j inclusive (i≤ji \leq j) is evaluated as:

nums[i] −- nums[i + 1] ++ nums[i + 2] −- nums[i + 3] +…+ \dots

where the signs alternate between addition and subtraction, beginning with addition for the first element nums[i].

Return the maximum alternating sum of any non empty subarray.

Constraints:

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

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Alternating Subarray Sum

Maximum Alternating Subarray Sum asks you to find the largest alternating sum of any nonempty subarray in an array, with signs starting positive and switching at each element. Values may be negative.

Statement

Given an array of integers nums, determine the maximum alternating subarray sum among all non empty subarrays of nums.

The alternating sum of a subarray starting at index i and ending at index j inclusive (i≤ji \leq j) is evaluated as:

nums[i] −- nums[i + 1] ++ nums[i + 2] −- nums[i + 3] +…+ \dots

where the signs alternate between addition and subtraction, beginning with addition for the first element nums[i].

Return the maximum alternating sum of any non empty subarray.

Constraints:

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

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