Ad
  • Default User Avatar

    Another thing is, looking for square is generally longer then apply power if I am not mistaken, so this 'miserable' time difference might be covered by that.

    By looking at memory complexity, and complexity in general, this solution isn't best practice at all, clever, maybe.

  • Custom User Avatar

    Sorting is already creating new lists in memory, regardless of squaring each value. Compared to the sorted operation, squaring each value is negligible and neither increases the time or space complexity.

    And generally speaking, optimizations where you can return early don't decrease the time complexity in the average case so aren't really used as a way to judge algorithms in problems like this.

  • Default User Avatar

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

  • Default User Avatar

    I like the compact solution you found, but:
    Since you use the "[i ** 2 for i in array1]" part you first generate a full list in memory, then check if it is the same as the other list.
    For long lists it is far more efficient to generate the squares element by element while checking, because you could find a different early on and just return false.

  • Default User Avatar

    Hi man, one hint:
    You can get rid of solution a1 because that is always >1, therefore it is not a converged solution.