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.
Clunky problem with elegant solution.
Yes, in general you should aim for time-complexity improvements (ie reduce the number of nested loops), rather than micro-optimisations
you need to implement a single-loop solution
This comment is hidden because it contains spoiler information about the solution
There is a subarray which sums to 6, which is
[4, -1, 2, 1]:I'm having some trouble with the test. Shouldn't [-2, 1, -3, 4, -1, 2, 1, -5, 4] be equal to 1, and not 6?
Yes, the current test requirements allow naive solutions to pass, and this kata is tagged performance. If other languages also have tests that are too easy, they should be updated too.
okay, so I just now translated Edward's
Ccode intoPython, which beautifully passed the sample tests, but timed out on the fixed / random tests, so that would appear to be a good why thatmultiplelanguages should be adaptedand gloriously, we have a piece of code to use as a litmus test (thank you
OP) I'll get back to this tomorrowbut why? Edward does not have an answer to why, Bob has not stated why, so this issue is lacking that particular directive.
I have not had a chance to look into why, so I still do not know why myself, but since I did the C translation
seven years agoI will look in detail tomorrow if it has not yet been resolved.Meanwhile, it is not just C with low array lengths: C++, C#, and Java all have random test arrays averaging around 40 to 50 in length.
Yes, the tests need to be hardened in C. Other languages test arrays tens of thousands of elements long, but the arrays in C have a max length of 42 for some reason.
This comment is hidden because it contains spoiler information about the solution
I understand the logic behind the solution now(though I did not solve it on my own). It requires a level of abstraction I'm not used to yet. Rather than checking each Subarray, it can be done in a single iteration.
Thank you.
This comment is hidden because it contains spoiler information about the solution
for some reason i didn't come to the obvious way of solving it and instead made a thrice-nested loop.
nice one, though.
The reference solution returns
truefor 8821. It's your code which is returning false for it.Loading more items...