Commit cebc87ca authored by Rafael Avaria Gutierrez's avatar Rafael Avaria Gutierrez

Merge branch 'MissingNumberJs' into 'master'

Missing number js

See merge request !1
parents 4b26b662 5747446c
function getFrecuency(arr) {
return arr.reduce((acc, ele) => {
if (acc.has(ele)) {
const i = acc.get(ele);
acc.set(ele, i + 1);
} else {
acc.set(ele, 1);
}
return acc;
}, new Map());
}
// Complete the missingNumbers function below.
function missingNumbers(arr, brr) {
const result = [];
const arrF = getFrecuency(arr);
const brrF = getFrecuency(brr);
for ( let value of brrF.keys()) {
if ( arrF.has(value)) {
if ( arrF.get(value) != brrF.get(value)) {
result.push(value);
}
} else {
result.push(value);
}
}
return result.sort(function(a, b) { return a - b; });
}
\ No newline at end of file
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