Missing Numbers

  • + 0 comments

    Python

    def missingNumbers(arr, brr):
        arr.sort()
        brr.sort()
    
        ai, bi = 0, 0
        res = []
        while ai < len(arr) and bi < len(brr):
            if arr[ai] > brr[bi]:
                if brr[bi] not in res:
                    res.append(brr[bi])
                bi += 1
            elif arr[ai] < brr[bi]:
                ai += 1
            else:
                ai += 1
                bi += 1
    
        res += sorted(set(brr[bi:]))
        return res