Created
December 3, 2022 18:18
-
-
Save iamargentum/e650ecc6d0e554f0dcbbd8ef8307f2d9 to your computer and use it in GitHub Desktop.
this program finds the lowest unused number from an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
someArray = [0, 1, 3] | |
contextSmallest = someArray[0] # considering the first element of the aray to be smallest | |
for i in range(1, len(someArray)): # finding the actual smallest number | |
if someArray[i] < contextSmallest: | |
contextSmallest = someArray[i] | |
smallestUnused = None # let's say | |
while smallestUnused is None: | |
temp = contextSmallest + 1 | |
if not (temp in someArray): # if just one more than the smallest is not present in the array, it must be the smallest unused number | |
smallestUnused = temp | |
else: | |
contextSmallest = temp | |
print("smallest unused is - ", smallestUnused) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment