Smallest Missing Number in Python

Problem Statement:

In the smallest missing number in Python, we are given a list of numbers, and we need to find the smallest missing number using the Python program. For example, [1, 2, 3, 3, 5, 7, 7, 4, 4, 9, 8]=>sorting=>[1, 2, 3, 3, 4, 4, 5, 7, 7, 8, 9], 6 is the smallest missing number.

Code for Smallest Missing Number in Python:

numbers = [1, 2, 3, 3, 5, 7, 7, 4, 4, 9, 8]
numbers.sort() # [1, 2, 3, 3, 4, 4, 5, 7, 7, 8, 9]
previous = 1
current_should_be = 1
i = -1
while True:
    if i>=0:
        previous=numbers[i]
    i += 1
    current = numbers[i]
    if current == previous or current == current_should_be:
        previous = current
        current_should_be = current + 1
        continue
    else:
        print(previous+1)
        break

Output:

Smallest Missing Number in Python

Also Read:

Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you