Missing Numbers

  • + 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 missing_numbers(arr, brr):
        # Time complexity: O(a + b)
        # Space complexity (ignoring input): O(a + b)
        arr_dict = {}
        for value in arr:
            if value in arr_dict:
                arr_dict[value] += 1
            else:
                arr_dict[value] = 1
    
        brr_dict = {}
        for value in brr:
            if value in brr_dict:
                brr_dict[value] += 1
            else:
                brr_dict[value] = 1
    
        missing_values = []
        for key in brr_dict.keys():
            if key in arr_dict:
                if arr_dict[key] <= brr_dict[key]:
                    missing_values.append(key)
            else:
                missing_values.append(key)
    
        missing_values.sort()
        return missing_values