Find the best contiguous section after optionally performing a limited trade operation to maximize the total active value.
You are given an array of integers representing the value of each section in a line. A contiguous section is considered active if its total contribution is maximized under the allowed trade rule.
At most once, you may perform a trade operation that changes how a chosen segment contributes to the final score. Your goal is to choose the best active section and, if beneficial, apply the trade so that the resulting score is as large as possible.
Return the maximum achievable score.
This is a practice-style rephrasing of the problem: the key task is to optimize over contiguous subarrays while accounting for one optional trade-like transformation.
nums.Return a single integer: the maximum score obtainable.
1 <= nums.lengthExample 1
Input
nums = [1, -2, 3, 4, -1]
Output
7
Explanation
A best active section is [3, 4] with score 7. If the trade rule helps, it should be incorporated into the same contiguous-optimization framework.
Example 2
Input
nums = [-5, -1, -3]
Output
-1
Explanation
When all values are negative, the best choice is the least negative single section.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.