Tap here to switch tabs
Problem
Submissions

Problem: Reverse Subarray To Maximize Array Value

med
30 min
Try to solve the Reverse Subarray To Maximize Array Value problem.

Statement

You are given an integer array nums. The value of an array is defined as the sum of ∣|nums[i] −- nums[i + 1]∣| across all 0≤0 \leq i << nums.length −1- 1.

You may select at most one contiguous subarray of nums and reverse it.

Return the maximum possible value of the array after performing at most one such reversal.

Constraints:

  • 2≤2 \leq nums.length ≤3imes104\leq 3 imes 10^4

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

  • The answer is guaranteed to fit in a 3232 bit integer.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Reverse Subarray To Maximize Array Value

med
30 min
Try to solve the Reverse Subarray To Maximize Array Value problem.

Statement

You are given an integer array nums. The value of an array is defined as the sum of ∣|nums[i] −- nums[i + 1]∣| across all 0≤0 \leq i << nums.length −1- 1.

You may select at most one contiguous subarray of nums and reverse it.

Return the maximum possible value of the array after performing at most one such reversal.

Constraints:

  • 2≤2 \leq nums.length ≤3imes104\leq 3 imes 10^4

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

  • The answer is guaranteed to fit in a 3232 bit integer.