1330. Reverse Subarray To Maximize Array Value Hard
1/**
2 * [1330] Reverse Subarray To Maximize Array Value
3 *
4 * You are given an integer array nums. The value of this array is defined as the sum of |nums[i] - nums[i + 1]| for all 0 <= i < nums.length - 1.
5 * You are allowed to select any subarray of the given array and reverse it. You can perform this operation only once.
6 * Find maximum possible value of the final array.
7 *
8 * Example 1:
9 *
10 * Input: nums = [2,3,1,5,4]
11 * Output: 10
12 * Explanation: By reversing the subarray [3,1,5] the array becomes [2,5,1,3,4] whose value is 10.
13 *
14 * Example 2:
15 *
16 * Input: nums = [2,4,9,24,2,1,10]
17 * Output: 68
18 *
19 *
20 * Constraints:
21 *
22 * 1 <= nums.length <= 3 * 10^4
23 * -10^5 <= nums[i] <= 10^5
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/reverse-subarray-to-maximize-array-value/
29// discuss: https://leetcode.com/problems/reverse-subarray-to-maximize-array-value/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn max_value_after_reverse(nums: Vec<i32>) -> i32 {
35 0
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_1330() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.