Commit 2244aaea authored by Gabrher's avatar Gabrher

missing numbers problem in python

parent 4b26b662
def missingNumbers(arr, brr):
dicA = convertArrToDic(arr)
dicB = convertArrToDic(brr)
missingNums = []
for key in dicB.keys():
if (not key in dicA) or dicA[key] != dicB[key]:
missingNums.append(key)
return missingNums
def convertArrToDic(arr):
dic = {}
for i in arr:
addToDic(dic, i)
return dic
def addToDic(dic, i):
if not i in dic:
dic[i] = 1
return
dic[i] = dic[i] + 1
arr = [11, 4, 11, 7, 13, 4, 12, 11, 10, 14]
print("input array A: ")
print(arr)
brr = [11, 4, 11, 7, 3, 7, 10, 13, 4, 8, 12, 11, 10, 14, 12]
print("input array B: ")
print(brr)
print("missing numbers: ")
print(missingNumbers(arr,brr))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment