Which is missing? (2) X90391


Statement
 

pdf   zip   main.py

We handle lists that contain n1n-1 integers, all between 00 and n1n-1 (both included), and all different. Therefore, exactly one of these nn numbers is missing. Which one?

Write a function missing(lst)missing(lst) that receives such a list and returns the missing number.

Precondition: we are ensured that the list lstlst received by the function will always fulfill the condition that it contains nonnegative integers less than nn, all different, where nn is one more than the length of lstlst (hence, n>0n > 0 is also guaranteed as the smallest list has length zero).

Sample session
>>> missing([2, 1, 0, 4])
3
>>> missing([1])
0
>>> missing([0, 1])
2
>>> missing([4, 3, 5, 6, 0, 1, 8, 9, 7])
2
>>> missing([])
0
Information
Author
Jordi Petit (adapted by José Luis Balcázar)
Language
English
Official solutions
Python
User solutions
Python