5 kyu

Maximum Subarray Sum II

274 of 544raulbc777

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)

Fundamentals
Data Structures
Algorithms
Mathematics
Logic
Sorting

Similar Kata:

Stats:

CreatedMar 12, 2016
PublishedMar 12, 2016
Warriors Trained2247
Total Skips378
Total Code Submissions5068
Total Times Completed544
Python Completions274
Ruby Completions48
JavaScript Completions213
D Completions2
Rust Completions14
Go Completions15
Total Stars86
% of votes with a positive feedback rating84% of 123
Total "Very Satisfied" Votes91
Total "Somewhat Satisfied" Votes25
Total "Not Satisfied" Votes7
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • raulbc777 Avatar
  • tachyonlabs Avatar
  • Voile Avatar
  • akar-0 Avatar
  • saudiGuy Avatar
Ad