Member-only story
Interview question: Search missing number in an array that contains integers from 0 to 20
When going on a Python developer interview, it is quite likely that you are going to be asked to create a few algorithms to solve common problems in the language.
In this blog post, I intend to solve the problem of searching for a missing number in an array that contains integers from 0 to 20.
The solution to this problem can be found in the following psuedocode:-
- Define the variable, num_lst, which is a list of integers from 0 to 20, with a few digits missing.
- Define the function, find_missing, which accepts a list as input.
- Within the function, create a for loop where the variable i will iterate through 0 to the length of the list, incrementing by one. During each iteration, if i is not in the list the function will print the missing number in the list.
The code in python for this algorithm can be seen below:-
I devised the above algorithm myself, but I did conduct a bit of research and did find another algorithm on a well known coding website. When I tested the algorithm, however, it didn’t work, and that is why I have not included it in this blog post.