Missing Numbers

Sort by

recency

|

105 Discussions

|

  • + 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
    
  • + 0 comments

    Python3 1 liner:

    return sorted(Counter(brr) - Counter(arr))
    
  • + 0 comments
    def missingNumbers(arr, brr):
        answer = []
        for element in arr:
            if element in brr:
                brr.pop(brr.index(element))
            else:
                if element not in answer:
                    answer.append(element)
        for element in brr:
            if element not in answer:
                answer.append(element)
        answer.sort()
        return answer
    
  • + 0 comments

    def missingNumbers(arr, brr):

    for a in arr:
        brr.remove(a)
    return sorted(set(brr))
    
  • + 0 comments

    c++

    vector<int> missingNumbers(vector<int> arr, vector<int> brr) {
        set<int> s;
    
        sort(arr.begin(), arr.end());
        sort(brr.begin(), brr.end());
    
        set_difference(brr.cbegin(),brr.cend(), arr.cbegin(),arr.cend(), inserter(s, s.begin()));
        
        return vector<int>(s.cbegin(), s.cend());
    }