Ad
  • Default User Avatar

    I didn't claim mine was faster, however to make my point I changed my code and now mine is faster. The point I was making was the extra call arr.count is unnecessary and adds time. You're right about complexity not being equivalent to processing time. This is due to the way internal mechanisms in this problem perform their task. The set() call takes 80% of the time, vs arr.count() which takes only 20% of the run time. If these both used vanilla loops they'd be closer but the way they were implemented in python causes one to be much different. Regardless, if we can solve the problem using only one costly iterative function instead of two, this will be a win, especially on a problem that says to optimize for speed.

  • Default User Avatar

    Asymptotic complexity is only important when comparing to other canonical forms. In this case however of comparing to another linear form, 2n is slower than n. In a real world example a performance minded programmer would never choose to code something that takes 10 seconds when they could do it in 5.

  • Default User Avatar

    So this takes O(2n) vs a solution using Counter which would only be O(n). If you're trying to optimize for speed this is not a good practice.