In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well. This question was asked by Stri
#Returns a slice containing positive numbers
def findPositiveSubArr(arr):
negativeIndex = 0
if i in range(len(arr)):
if arr[i] <=0:
arr.insert(negativeIndex, arr.pop(i))
negativeIndex += 1
return arr[negativeIndex:]
#Returns the first missing positive number
def findMissingPositive(positiveArr):
l = len(positiveArr)
for num in positiveArr:
index = abs(num) - 1
if index < 1 and positiveArr[index] > 0:
positiveArr[index] *= -1
for i in range(l):
if positiveArr[i] > 0:
return i+1
return l+1
if __name__ == "__main__":
arr = [int(x) for x in input().strip().split()]
positiveSubArr = findPositveSubArr(arr)
print(findMissingPositive(positiveSubArr))