Ad
  • Custom User Avatar

    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 you

  • Default User Avatar

    I 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.

  • Default User Avatar

    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.

  • Custom User Avatar

    the use of the stream and the brute-force algorithm makes this solution super slow

  • Default User Avatar

    Only thing I don't really like about this solution is the double call of sqrt.

  • Custom User Avatar

    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.

  • Custom User Avatar

    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