Missing Numbers

  • + 3 comments

    Simple in Python 3 :-)

    from collections import Counter
    n,arr=int(input()),list(map(int,input().split()))
    m,brr=int(input()),list(map(int,input().split()))
    a,b=Counter(arr),Counter(brr)
    print(*(sorted((b-a).keys())))
    

    Explanation:

    Let us take an example :
    n=10
    arr=11 4 11 7 13 4 12 11 10 14
    m=15
    brr=11 4 11 7 3 7 10 13 4 8 12 11 10 14 12
    a=Counter(arr)=Counter({11: 3, 4: 2, 7: 1, 13: 1, 12: 1, 10: 1, 14: 1})
    b=Counter(brr)=Counter({11: 3, 4: 2, 7: 2, 10: 2, 12: 2, 3: 1, 13: 1, 8: 1, 14: 1})
    b-a=Counter({7: 1, 3: 1, 10: 1, 8: 1, 12: 1})
    (b-a).keys()=dict_keys([7, 3, 10, 8, 12])
    sorted((b-a).keys())=3 7 8 10 12