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.
Was testing your function and noticed that it gave me a bad access error, probably due to the recursion depth, when calculating
factors(100_003)
. That said, I appreciate the way you thought of this recursively, very smart.This comment is hidden because it contains spoiler information about the solution
I agree with antong01. This problem is best solved in
O(n)
by not sorting either array, but instead making use of a dictionary. Most of the solutions submitted either use sorting which results inO(n log n)
or searching through an array, which results inO(n^2)
overall. While simple and concise to write, they don't scale as well.Please mark your posts as having spoiler content even in Solutions when they have spoilers.
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 suppose I should have incremented i in the else clause of my guard statement, as right now given an invalid character it would infinite loop.