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 too bad
This solution is too slow. If you run it now, it'll get timeout error!
Because 1 is not a prime number.
I was wondering the same, why can't we use "return true" instead of
return num >=2
This will take forever if the number is 290348029438029348029348029348029348029384029384029384
Solution no longer runs within the required time
Its Time complexity is O(n) times
This was my original solution as well but for me it time out and fails ¯_(ツ)_/¯
Yes as said above square root is better..But you can still improve it better by checking whether the number is even before you run the loop because an even number can never be a prime number.This way you can increase your loop with 2 steps starting from 3 instead of just 1 and when an even number is provided your code only need to run once because it will automatically return false before even running the loop
spoiler flag...
This comment is hidden because it contains spoiler information about the solution
I thought so too, but notice if the number is < 2, it'll only iterate twice before it reaches that statement.
This comment is hidden because it contains spoiler information about the solution
Why num % i is NaN? It can't be compared with 0
we may add 'break' in if statement and don't need to check another dividers
Loading more items...