Given an array nums of integers, find three non-overlapping subarrays with maximum sum.
Return the total sum of the three subarrays
Example:
Input: [2, 3, -8, 7, -2, 9, -9, 7, -2, 4]
Output: 28
Explanation: Subarrays [2, 3], [7, -2, 9] and [7, -2, 4]
have the maximum sum of 28
Note:
- Subarrays must be non-empty
- nums contains at least three numbers
Walkthroughs of the solution. Try the steps first, then watch to compare approaches.
Solution #3 · O(n^2)
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check