Company: Adobe_15Aug
Difficulty: medium
Maximum Gross Value Problem Given an integer array arr of length n , choose a valid triplet of boundary indices (i, j, k) . The gross value of the triplet is defined as: grossValue = sum(1, i) - sum(i, j) + sum(j, k) - sum(k, n + 1) where sum(x, y) is the sum of all elements in the subarray arr[x] through arr[y - 1] . If the subarray is empty (that is, x >= y ), the sum is 0 . Indices are 1-based. A triplet (i, j, k) is valid if it satisfies 1 <= i <= j <= k <= n + 1 . Find the maximum possible gross value among all valid triplets. Input The function getMaximumGrossValue receives an integer array arr of length n . In the custom test format, the first line contains n , followed by n lines each containing one array element. Output Return a long integer -- the maximum possible gross value. Constraints 1 <= n <= 3000 -10^9 <= arr[i] <= 10^9 Examples Example 1 Input: arr = [-5, 3, 9, 4] Output: 21 Explanation: Selecting i = 1 , j = 2 , k = 5 : sum(1, 1) = 0 (empty