5 kyu
Maximum Subarray Sum II
276 of 547raulbc777
Loading description...
Fundamentals
Data Structures
Algorithms
Mathematics
Logic
Sorting
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This Kata has some tricky not obvious conditions, which made it difficult and annoying for solving! My strong dislike to this Kata!
Which order the subsets are expected?
I cannot get pass the random tests, no matter how I order the results or sort them by some matter the test never passes
python new test framework is required. updated in this fork
.
expected [ [ [ 76, 97, -5, 29, -48, 31, 80, 57, +0 ], [ 76, 97, -5, 29, -48, 31, 80, 57 ] ], 317 ] to deeply equal [ [ [ 76, 97, -5, 29, -48, 31, 80, 57 ], [ 76, 97, -5, 29, -48, 31, 80, 57, +0 ] ], 317 ]
genious
Go translation
Same case before. I can't approve it. :(
I've updated the link, it should be approvable now.
Well, it was not, I had to do a new fork that didn't include any change... Merge conflict bugs... I merged and approved everything, it's fine :)
Rust translation, should be approved before D translation to avoid merge conflict, since D updates the description for more languages.
:( sorry
Don't worry, I'll fix this right now. The only inconvenient is the translation page will contain duplicate translations.
D translation
Approved. +1 Sorry for approving this one first before Rust translation. :(
Issues still need to be fixed...
The design of the output is bad. Returning a one dimensional array or multidimensional one for the first element, depending on what you find, isn't pertinent and makes it impossible to translate to many languages. Independently, a tuple would be a better choice for Python.
Hi Raul,
I've done it in JS:
Either the description and the tests are incomplete (fixed tests), or there is a problem with the internal solution (edit: or the random generator):
Problems being:
...56,-56,...
for one part: should we keep it or not?Note that going through the array right->left with the current requirements would lead to this overlapping thing, but not going left->right. So maybe it would be better to forbid contiguous opposite values in the inputs. If you keep them, you'll need to create specific tests for that (both with the pair before and/or after the smaller subarray)
side note: you really should use one unique output type. =>
[[[...]], n]
for single matches too.the issue is worse than that:
[5, -3, 1, 2, -4, 1, 3, 0]; max_sum = 5
expected answer:
[ [ [5], [5, -3, 1, 2], [5, -3, 1, 2, -4, 1, 3], [5, -3, 1, 2, -4, 1, 3, 0] ], 5 ]
the contiguous opposites are just a particular case of the more general problem: the tests count the subsequences that have prefixes/suffixes that sum to
0
as valid. the easiest thing to do would be to make that more clear in the descriptionAnother suggestion: why returning
[sub_array, max_sum]
when there is only one sub-array reaching the maximal sum, instead of[[sub_array], max_sum]
- the default result in all the other cases? Isn't it better to harmonize the len(...) == 1 case also?Yes , that problem here is very annoying . other format for one element other than more than one
As the kate is translated, you should remove the
/train/python
in your link to the previous kata as players may not have solved in Python.Better, consider using this link as it doesn't use any id:
Done. Thanks!
Do you also know how to enable Python 3 support? It should be good to enable it as there are some elegant solutions for this kata with
itertools.accumulate
.@lechevalier
See my comment on Find the Most Probable Sum Value or Values, in Rolling N-dice of n Sides. I think there's something wrong with caching, but I haven't investigated enough to open an issue on GitHub yet.
I've also read your comment on some other kata (or on gitter? I forgot) trying to enable Python 3. Can you try it and let me know?
It was on gitter on zellerede's katas here and here. At last, I have been able to add Python 3.x support, thank you! Now, if you want to give these katas a try, I'm quite sure you won't be deceived (well the second one gave me a hard time!)
@lechevalier I'm glad it worked, I'll try to open an issue about this soon. Bookmarked both :)
Two spelling mistakes in the description! ISSUE!!!! ISSUE!!!!!!
"Mathias Metzer" -> "Matthias Metzger"
Please fix as fast as you can! :-) :-)
Wow... what's this? Haven't noticed this description line:-))... Not really important... Steefeen and Raaaaul:-)!
Maybe he meant a different person. :D Not thanks to "Matthias Metzger", but to "Mathias Metzer"! :D :D
Fixed the mistake about the name Matthias. Thanks to SteffenVogel_79 for the observation, so
the issue is marked as solved by raulbc777
✓</font
:-))! Funny community here;-)!
Hi Raul, i think there's an error in your random tests (here i used Javascript), look here:
As you can see, the second one in my solution is your (single) solution, my first one is another solution with same sum=574. The last part of your solution (-89,9,-76,53,3,-50,78,72) is 0, so there are two correct solutions. There are generally 1-4 errors of this form inside your random block (rest works for me).
PS: After 4 tries my solution was accecpted, so you can have a look;-)...
Oh thank you very much. I appreciate your feedback. I'll check it this morning.
This comment has been hidden.
This comment has been hidden.
Also, agree with unnamed - the special case when there is exactly one solution is inelegant, unnecessary and makes for extra work both when producing and consuming the output. (Consuming isn't applicable to a kata, but would be so IRL.)
It can be proved that the probability of having more than one solution decreases when the array length increases. For an average length of 150 numbers, random tests will output almost always one solution. From my point of view I'd like to have, in IRL, a differentiated output when a have an exceptional case, as a signal to call my attention. (the double brackets would do so :)) (only a point of view)
Could do with random test with more than one solution.
Could also do with tests with more than two solutions.
The details might mention we're not interested in sums <= 0, and we have to return [] in that case.
Good point. It's fixed in the instructions.
It looks like an abuse of dynamic typing. First there's an
if
to return the result, then there would beif
s wherever it's used.I'm sorry Unnamed for my late response. I'm sure that you gave me a good observation but I didn't get it. I'm keen on receiving your suggestions and observations.
It's a special case with a different return type when there's only one answer. In this case the first item of the pair to return is the answer itself rather than a list of length 1 containing the answer. That requires some extra code handling the special case both when returning the answer and when processing it (if it were a real world task).
I'll check it thanks.
Random Tests fail if array of max subsets is in a different order:
Can the description be updated to specify in which order the max subsets are expected?
The order matters. It says that if we have two or more sub-arrays, the one that should be output first is the one that appears first in the array in the direction from left to right. The order that you gave is right and mine is wrong. Give me 5 minutes to fix that.
It's fixed, if you are satisfied with the test I'll appreciate your message. Thanks for the feedback and for your time solving this kata.
Perfect!
Thanks again!
I have the same issue with random tests (Golang, wrong order)