Missing number in array from 1 to 100 - Python
Q#1
I found another interest interview question on some blog... (https://simpleprogrammer.com/programming-interview-questions/)
So, I decide to solve these question one by one by python
Question 1:
How do you find the missing number in a given integer array of 1 to 100?
We need input from user for array. But don't worry about it. Here Python code also do it for us randomly in every time.
Let's Code and Check...
CODE:
import random
a = []
while len(a) < 90:
ranAdd = random.randint(1,100)
if ranAdd in a:
pass
else:
a.append(ranAdd)
a.sort()
print(a)
missnum = []
for i in range(1,101):
if i in a:
pass
else:
missnum.append(i)
print(missnum)
-------
By
PyKAR
Comments
Post a Comment