def Differentiate(arr, size):
j = 0
for i in range(size):
if (arr[i] <= 0):
arr[i], arr[j] = arr[j], arr[i]
j += 1 # increment count of non-positive integers
return j
def GetMissiing(arr, size):
for i in range(size):
if (abs(arr[i]) - 1 < size and arr[abs(arr[i]) - 1] > 0):
arr[abs(arr[i]) - 1] = -arr[abs(arr[i]) - 1]
for i in range(size):
if (arr[i] > 0):
return i + 1
return size + 1
def CheckMissing(arr, tempSize):
s = Differentiate(arr, tempSize)
return GetMissiing(arr[s:], tempSize - s)
InputArr = [3, 1, 2, 5, 3, 7, 7]
Input_arr_size = len(InputArr)
MissingTerm = CheckMissing(InputArr, Input_arr_size)
print("\nSample Input-1")
print("The smallest positive missing number is ", MissingTerm)
InputArr = [5, 5, 2, 3, 1, 8, 8, 4 ]
Input_arr_size = len(InputArr)
MissingTerm = CheckMissing(InputArr, Input_arr_size)
print("\nSample Input-2")
print("The smallest positive missing number is ", MissingTerm)
Comments
Leave a comment