Skip to content

Instantly share code, notes, and snippets.

@joxer
Created March 14, 2019 08:34
Show Gist options
  • Save joxer/e29dc31b33f250e25e020690e82d2bc6 to your computer and use it in GitHub Desktop.
Save joxer/e29dc31b33f250e25e020690e82d2bc6 to your computer and use it in GitHub Desktop.
def find_lowest_not_exists(array):
max_len = len(array)-1
min = 0
ri = max_len
while(ri > 0):
idx = 0
while(idx < ri):
if(array[idx] <= min):
array[ri], array[idx] = array[idx], array[ri]
ri -= 1
else:
idx+=1
if(array[ri] <= min):
ri-=1
idx2 = 0
new_min = array[idx2]
while(idx2 <= ri):
if(array[idx2] < new_min ):
new_min = array[idx2]
idx2+=1
print(array,min,new_min)
if(new_min - min > 1):
return max(min+1,new_min-1)
min = new_min
return new_min+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment