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
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
I agree. Replace "/" with "//" and this solution is pretty close to perfect.
I wrote a recursive O(n) implementation, but I think this solution is closer to "best practice". Start with this solution, because it is simple and easy to read, understand, and maintain. If you need faster performance, and only if you need faster performance, profile your code and find the bottleneck. Finally, if this part of the code turns out to be the bottleneck, now you can implement a faster algorithm. As Donald Knuth said, "premature optimization is the root of all evil (or at least most of it) in programming".