dailycodingproblems/find_least_positive_integer_missing.cpp
/* Find the smallest positive missing number 
in an array that contains all positive integers */
Find the smallest positive missing number
in an array that contains all positive integers
Find the smallest positive missing number in an array that contains all positive integers
int findMissingPositive(int arr[], int size) 
{ 
	int i; 
	for (i = 0; i < size; i++) { 
		if (abs(arr[i]) - 1 < size && arr[abs(arr[i]) - 1] > 0) 
			arr[abs(arr[i]) - 1] = -arr[abs(arr[i]) - 1]; 
	} 
	for (i = 0; i < size; i++) 
		if (arr[i] > 0) 
			return i + 1; 
	return size + 1; 
}
int findMissingPositive ( int arr [ ] , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) { if ( abs ( arr [ i ] ) - 1 < size && arr [ abs ( arr [ i ] ) - 1 ] > 0 ) arr [ abs ( arr [ i ] ) - 1 ] = - arr [ abs ( arr [ i ] ) - 1 ] ; } for ( i = 0 ; i < size ; i ++ ) if ( arr [ i ] > 0 ) return i + 1 ; return size + 1 ; }
Find the smallest positive missing number
in an array that contains all 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 