Missing Numbers

Sort by

recency

|

104 Discussions

|

  • + 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());
    }
    
  • + 0 comments

    Typescript

    function missingNumbers(arr: number[], brr: number[]): number[] {
        arr.sort((a, b) => a - b);
        brr.sort((a, b) => a - b);
    
      let set = new Set();
      let counter = 0;
    
      for (let i = 0; i < brr.length; i++) {
        if (arr[counter] !== brr[i]) {
          set.add(brr[i]);
          continue;
        }
        counter++;
      }
    
      return Array.from(set.values()) as number[];
    
    }