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.
Well, your solution is better where it matters while being just as clean as mine. There's no arguing against that
Well, it's a time and memory issue. I tried 30,000,000 with both functions and it took more than 10x the time. I then tried 300,000,000: O(1) gave me the answer in 22ms. O(n) got a memory error.
Well, apart from the O(n) vs O(1) issue, the code is short, clean and easy to understand.
Not sure why this is getting best practices votes. Why use O(n) complexity when there's a O(1) solution that doesn't require much mathematic knowledge to discover?
Yeah, I totally refactored this just after I submitted ;)