Maximum Sum Score of Array - Problem
You are given a 0-indexed integer array nums of length n.
The sum score of nums at an index i where 0 <= i < n is the maximum of:
- The sum of the first
i + 1elements ofnums - The sum of the last
n - ielements ofnums
Return the maximum sum score of nums at any index.
Input & Output
Example 1 — Mixed Positive Numbers
$
Input:
nums = [1,4,3,7,4]
›
Output:
19
💡 Note:
At index 0: left=[1] sum=1, right=[1,4,3,7,4] sum=19, score=19. At index 4: left=[1,4,3,7,4] sum=19, right=[4] sum=4, score=19. Maximum score across all indices is 19.
Example 2 — Single Element
$
Input:
nums = [5]
›
Output:
5
💡 Note:
Only one element, so both left sum and right sum equal 5. Score = max(5,5) = 5.
Example 3 — Negative Numbers
$
Input:
nums = [-3,-5,2,8]
›
Output:
10
💡 Note:
At index 2: left sum = -3+(-5)+2 = -6, right sum = 2+8 = 10, score = max(-6,10) = 10. At index 3: left sum = -3+(-5)+2+8 = 2, right sum = 8, score = max(2,8) = 8. Maximum score is 10.
Constraints
- 1 ≤ nums.length ≤ 105
- -106 ≤ nums[i] ≤ 106
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code