find missing number in array

Go Back home

Given an array, e.g:

1 [1, 2, 3, 4, 5, 6, 7, 8, 10]

And its length:

1 10

Write a python program to find the missing number.

1 from functools import reduce
2 from operator import ixor
3 
4 find_missing = lambda arr, l:  reduce(ixor, arr) ^ reduce(ixor, range(l+1))
5 
6 assert find_missing([1, 2, 3, 4, 5, 6, 7, 8, 10], 10) == 9