def smallest_missing_positive_integer(nums): i = 0 while i < len(nums): correct_spot = nums[i] - 1 if 0 <= correct_spot < len(nums) and nums[i] != nums[correct_spot]: nums[i], nums[correct_spot] = nums[correct_spot], nums[i] else: i += 1 for i in range(len(nums)): if i + 1 != nums[i]: return i + 1 return len(nums) + 1 # Driver code def main(): input_array = [[1, 2, 3, 4], [-1, 3, 5, 7, 1], [1, 5, 4, 3, 2], [-1 , 0, 2, 1, 4], [1,4,3]] x = 1 for i in range(len(input_array)): print(x, ".\tThe first missing positive integer in the list ", input_array[i], " is: ", sep = "") print("\t" + str(smallest_missing_positive_integer(input_array[i]))) print("-" * 100) x = x + 1 if __name__ == '__main__': main()