Sales by Match

  • + 0 comments

    Python best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

    def sales_by_match(n, ar):
        #Time complexity: O(n)
        #Space complexity (ignoring input): O(n)
        socks_dict = {}
        for sock in ar:
            if sock in socks_dict:
                socks_dict[sock] += 1
            else:
                socks_dict[sock] = 1
    
        total_pairs = 0
        for values in socks_dict.values():
            total_pairs += values // 2
    
        return total_pairs