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
now that
Array.prototype.sort()
is stable these solutions are correctBrute force should've been stated in the description of the code, but it does encourage people to write more efficent code.
I initally decided to generate all of the permutations and then give back the next biggest one but tests stopped me from doing that.
ahhh! i was wondering that!
fixed
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
It is based on the original language, so cannot be changed
same in Ruby with
[4,5]
expecting 1 instead of 0Yeah I don't think it would time out since n is being divided smaller like tacoslayer said. You are right that there's no need to keep iterating once it has reached the square root of the number,
BUUUUuuuuut, because this algorithm divides n each time it finds a factor, it will usually get cut short before then anyway. It would only iterate all the way through when n has been reduced to a prime number. not really such a problem generally... but there's no reason not to cut it off at the square root since not all prime numbers are small........it'd be the difference for example between iterating 151051 times and iterating only 388 times.
Optimising your solution may be possible, but this is not a kata issue. Closing.
This comment is hidden because it contains spoiler information about the solution
OP solved it, closing
This comment is hidden because it contains spoiler information about the solution
Loading more items...