Ad
  • Custom User Avatar

    Building up on the previous comment... Look at: https://wiki.python.org/moin/TimeComplexity

    x in list has O(n) complexity, while x in set is O(1) [assuming collisions are unlikely].

    So, considering array1 and array2 have length n and m, this code using list has complexity O(n * n * m + n * log n) which can be simplified as O(n**2 * m), while using set can reduce it to O(n * m + n * log n).

  • Custom User Avatar

    For the eq method, you're already representing the fractions in their most simplified form, so isn't it enough to just compare the self.top with other.top, and simmilarly for bottom?

    i.e. return self.top == other.top and self.bottom == other.bottom

  • Custom User Avatar

    I know writing this is a great exercise!
    But it is already available in the Python standard library (from fractions import Fraction)