Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Do you mean the most optimized solution can be O(n*sqrt(n)) ? Cuz the one above is not I believe. You have n numbers and for each one you do n/2 steps, so its O(n^2) worst case scenario right ?

  • Custom User Avatar

    Just a minor optimization upgrade ( even though its still O(n^2)).. you only have to check numbers until n/2 since numbers between n/2 and n can't be divisors of n.

  • Custom User Avatar

    Good one, same as mine but maybe clear.

    Unfortunately, there's no clever way of doing this, it has to be O(n^2), because they way f(sum of squared divisors of number inluding itself) behaves is very erratic and unpredictable.
    You can maybe skip prime numbers since they will always give a false result, but not enough to get it below O(n^2).

  • Custom User Avatar

    So why do you map the characters in the first string, which can potentially be very big, than doing it on the 2nd one ? It helps with performance in average cases.
    str2 will aways be shorter than str1 otherwise the function returns false

    e.g
    str1 has 1million characters
    str2 has 5 characters
    str2 can be made out from the first 10 characters of str1
    you have just saved a lot of space if you also keep track of when keys in the map reach 0.
    Check my solution for how to get max performance for this.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Hey,

    I struggled a bit with the math part of this part. Maybe you could explain a couple of things.

    The whole Math.atan2(y,x) gives me a headache. What are the potential values of this and on what part of the circle is the 0 ?

    what does the conversion (1-Math.atan2(y,x) / Math.PI) * 180 do exactly ? What will be the new range of your angle?

    Where does the 18 come from when searching for the slice of the circle the angle falls on ?

    Cheers, very clean solution.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution