Skip to content

Instantly share code, notes, and snippets.

@iamargentum
Created December 3, 2022 18:18
Show Gist options
  • Save iamargentum/e650ecc6d0e554f0dcbbd8ef8307f2d9 to your computer and use it in GitHub Desktop.
Save iamargentum/e650ecc6d0e554f0dcbbd8ef8307f2d9 to your computer and use it in GitHub Desktop.
this program finds the lowest unused number from an array
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