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.
This comment is hidden because it contains spoiler information about the solution
Writting down the detailed steps on a paper helped me to clarify the algo ;)
Somethings wonky with negative test outputs.
I have derived the negative extension myself, as well as checked it against Wikipedia's...and yet it still gives errors on random negative numbers
Cheers! It looks like you solved the kata.
I suppose you've figured out that
source.Count()
enumerates the source and which is why it fails the tests. Using Count as an existence test is bad because the enumerable could be very large and costly to determine when all that is desired to know is whether there is at least one. The LINQ operator for existence tests is Any which does such a test -- but even calling Any would fail the test since it enumerates the first element of the enumerable.Imagine the following enumerable for a test case in CodeWars:
Implementations with early-out checks for
source.Count()
orsource.Any()
will encounter the CodeWars timeout and have their executions stopped.Thanks for your questions and for doing the kata.
No, it should not be negative. Yes, you are missing the "Hint I" from the description.
Hello,
How fast was your solution?
Mine passes n = 10e7 in 1.394 seconds but it still times out during the random test.
[edit] for anyone wondering the threshold is to be able to return n=10e7 in approximately less than 1 second.