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.
all
returns as soon as it finds the first negative. there's no advantage in usingany
instead ofall
.Testing computational complexity is a real pain. We can't really test worst case complexity as it depends on the algorithm used. We could try average complexity, but that needs extensive test with big input (because we want the asymptotic complexity). I think it's impossible to test thoroughly on this platform since tests are limited in time.
We could possibly test for an upper bound rather than an asymptotic behavior (no more than 4*n access operation for example), this would allow us to test on smaller set of data. However, that requires to monitor access operation, and it's impossible here. Firstly because some languages like JavaScript don't allow to override array access operators for example, but also because the algorithm being tested might as well work on a copy of the input (converting it into another data structure).
I'd conclude that your initial approach is good enough, as long as it only yields false positives but isn't too restricting to yield false negatives. It's just an incentive to write efficient code :) In the end we're here to train, these are not exams :D
This takes longer than 6 seconds to load, so it was failing for me. I was able to load for k = 400, but I'm concerned that this assertion may cause the tests to become too brittle and may break existing solutions. There's also to guarantee that the assertion will really weed out non O(N) solutions. Testing for time complexity is a real pain. I appreciate the feedback!
This comment is hidden because it contains spoiler information about the solution
Marking issue as resolved.
Fixed. Here are the changes that I made:
I'd be interested to see if your initial O(N^2) solution still works.
you upvote a beta kata by choosing ready after you have solved it
How do we upvote katas in beta process ? I can't find a place where I can click on the upvote counter to add mine. Thank you for your help
Interesting. I'm going to add some randomized tests tonight. I may need to throw out the O(n) test because I'm not sure if it can be truly tested, but I'll try.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution