human
Find the smallest positive number missing from an unsorted array | Set 1 | Utility function that puts all non - positive ( 0 and negative ) numbers on left side of arr [ ] and return count of such numbers.
increment count of non - positive integers.
Find the smallest positive missing number in an array that contains all positive integers.
Mark arr [ i ] as visited by making arr [ arr [ i ] - 1 ] negative . Note that 1 is subtracted because index start from 0 and positive numbers start from 1.
Return the first index value at which is positive.
1 is added because indexes start from 0.
Find the smallest positive missing number in an array that contains both positive and negative integers.
First separate positive and negative numbers.
Shift the array and call findMissingPositive for positive part.
Driver code"
Solution in Python:
 ... Can you provide a code to find the smallest positive number missing from an unsorted array and the other steps required?
assistant
#Here is code to find the smallest positive number missing from an unsorted array and the other steps required.
 def segregate ( arr , size ) :
	j = 0
	for i in range ( size ) :
		if ( arr [ i ] <= 0 ) :
			arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
			j += 1
	return j
def findMissingPositive ( 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 findMissing ( arr , size ) :
	shift = segregate ( arr , size )
	return findMissingPositive ( arr [ shift : ] , size - shift )
arr = [ 0 , 10 , 2 , - 10 , - 20 ]
arr_size = len ( arr )
missing = findMissing ( arr , arr_size )
print ( " The ▁ smallest ▁ positive ▁ missing ▁ number ▁ is ▁ " , missing )