find missing number in array code example
Example 1: find the missing value in an integer array javascript
let a = [5, 7],
count = 10,
missing = []
for (let i = 1; i <= count; i++) {
if (a.indexOf(i) === -1) {
missing.push(i)
}
}
console.log(missing)
Example 2: FIND MISSING NUMBER IN AN ARRAY IN PYTHON
def get_missing_summatin(a):
n = a[-1]
total = n*(n+1)//2
summation = 0
summation = sum(a)
result = total-summation
print(result)
a = [1,2,3,5,6,7]
get_missing_summatin(a)