Class Solution
java.lang.Object
g1301_1400.s1330_reverse_subarray_to_maximize_array_value.Solution
1330 - Reverse Subarray To Maximize Array Value.<p>Hard</p>
<p>You are given an integer array <code>nums</code>. The <em>value</em> of this array is defined as the sum of <code>|nums[i] - nums[i + 1]|</code> for all <code>0 <= i < nums.length - 1</code>.</p>
<p>You are allowed to select any subarray of the given array and reverse it. You can perform this operation <strong>only once</strong>.</p>
<p>Find maximum possible value of the final array.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [2,3,1,5,4]</p>
<p><strong>Output:</strong> 10</p>
<p><strong>Explanation:</strong> By reversing the subarray [3,1,5] the array becomes [2,5,1,3,4] whose value is 10.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [2,4,9,24,2,1,10]</p>
<p><strong>Output:</strong> 68</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li>
<li><code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxValueAfterReverse
public int maxValueAfterReverse(int[] nums)
-