Maximum Subarray Sum II
Description:
Take a look to the kata Maximum Subarray Sum
https://www.codewars.com/kata/maximum-subarray-sum
In that kata (if you solved it), you had to give the maximum value of the elements of all the subarrays.
In this kata, we have a similar task but you have to find the sub-array or sub-arrays having this maximum value for their corresponding sums of elements. Let's see some examples:
[-2, 1, -3, 4, -1, 2, 1, -5, 4] returns [[4, -1, 2, 1], 6]
If in the solution we have two or more arrays having the maximum sum value, the result will have an array of arrays in the corresponding order of the array, from left to right.
[4, -1, 2, 1, -40, 1, 2, -1, 4]) returns [[[4, -1, 2, 1], [1, 2, -1, 4]], 6] # From left to right [4, -1, 2, 1] appears in the array before than [1, 2, -1, 4].
If the array does not have any sub-array with a positive sum of its terms, the function will return [[], 0]
.
See more cases in the Example Test Cases Window. Enjoy it!
Thanks to smile67 (Matthias Metzger from Germany for his important observations in the javascript version)
Similar Kata:
Stats:
Created | Mar 12, 2016 |
Published | Mar 12, 2016 |
Warriors Trained | 2247 |
Total Skips | 378 |
Total Code Submissions | 5068 |
Total Times Completed | 544 |
Python Completions | 274 |
Ruby Completions | 48 |
JavaScript Completions | 213 |
D Completions | 2 |
Rust Completions | 14 |
Go Completions | 15 |
Total Stars | 86 |
% of votes with a positive feedback rating | 84% of 123 |
Total "Very Satisfied" Votes | 91 |
Total "Somewhat Satisfied" Votes | 25 |
Total "Not Satisfied" Votes | 7 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |