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.
Reinventing List.toString() seems like a bad practice.
Just make a list and return it as a String and it will do the
[a, b, c]
for youI used the following method to calculate sumSquareFactors... for loop with i = 2 -> upperLimit where the upper limit is changed each time you find another number that is the factor. so that upperLimit = givenNumber / i. Not sure if optimal.
I was going to reply with these same critiques but I see someone else beat me to it. Anything using streams tends to look clever but there's no excuse for calling the same function twice for the same values. It's even called here a third time for every number that's a factor.
the use of the stream and the brute-force algorithm makes this solution super slow
Only thing I don't really like about this solution is the double call of sqrt.
I agree with everything above, but there is another problem.
-prefer performance over making your life easy or making your code shorter
A stream in this case is much slower than prime factorization followed by permutation. During my tests, the stream solution (even using n/2) takes about 80 milliseconds for 1-250. Prime factorization and permutation takes 2. When you bump the range up to 1-24000 it's 4100ms for streams and 150ms for prime factorization and permutation. Don't use a tool when it's inappropriate to do so.
Nice solution. Help me to remember about the usage of filter and range functions in Stream API. What I couldn't avoid to notice is that you are calling sumOfSquareDivisors three times for each number