Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Your solution fails following tes cases:
I may be misunderstanding the question - but you do know the contents of the array, as this is passed into the function you are making.
Arrays can be accessed in most languages like so - assumeing I have an array called "MyArray"
MyArray[0] - this would grab the first value of the array, MyArray[2] would grab the 3rd and so on.
You can find the length of the array in - for example C#, by using MyArray.Length
So with this in mind, you should be able to loop through an array and find the max sum
I agree with the poster above me - it would help to draw an array on a piece of paper, and figure out how you would do this manually.
Yes, once you understand the objective of the kata, you have to come up with an algorithm/program that finds the result yourself!
As always, if you are a bit confused, it is a good idea to try with the given example and use a pen and paper (old school) before trying to write code - how would you solve this kata on paper in "English/words".
For your 2nd question, I don't understand 100% - the "length of the optimum subarray" can range from 0 to L (where L is the size of the input) - for example:
[-3,-6,-1]
-> for this given input, the correct answer for the maximum subarray sum is 0; this occurs when you take the empty subarray[]
with no elements in it (any other subarray would contain a negative number so it would be less than 0)[5,9,100,5,2]
-> for this given input, the correct answer for the maximum subarray sum is 5+9+100+5+2=121, when you take the entire array of length 5.Hi - you have to find the maximum sum you can make from the given array, by selecting a contiguous (this means, "all side by side in the original array") subarray.
For example: