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 code is wrong because upon
cnt
exceedsn
, each element after the first occurrence of such cases will be continuously removed fromcopy
until the last element. Whilst the task asks us to remove elements until there are<= n
remaining in the original array.Not only you are modifying the original array which is bad practice, but also your conditional check is wrong. (Re-read the description)
Basically, you are trying to find
n
by adding your current 'step', whether positive or negative.starting at a total of
0
,on step 1 you'll add
1
or add-1
on step 2 you'll add
2
or add-2
on step 3 you'll add
3
or add-3
What ever it takes to reach the value of
n
How do I share this to friends that aren't on Codewars
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Thanks, but how does that come about? I get mutating the input is usually a no-no but how does that affect the tests?
I was modifying the input, don't do that
Don't modify the input.
Don't modify the input.
When testing in JS, random tests always expects an empty string instead of the string it actually asks to be returned. Works good for sample tests. Is this an error? Or I'm missing something...
Have a problem where all the random test cases are expecting '' while my code returns various strings that seem to match the numbers submitted. Is there a problem with this kata?
Why was Voile's answer downvoted?
Voile is correct - the example returns 6 because from the input (-2, 1, -3, 4, -1, 2, 1, -5, 4) you have to find the sequence which yields the highest sum.
That (as Voile correctly states) is "4, -1, 2, 1" because 4 - 1 = 3, then 3 + 2 = 5, then 5 + 1 = 6. There are negative numbers before (-3) and after (-5) this sub-sequence so the sub-sequence in the result is the yields the highest sum.
Loading more items...