human
First strictly smaller element in a sorted array in Java | Python3 program to find first element that is strictly smaller than given target.
Minimum size of the array should be 1.
If target lies beyond the max element , than the index of strictly smaller value than target should be ( end - 1 ).
Move to the left side if target is smaller.
Move right side.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to first strictly smaller element in a sorted array in Java and the other steps required.
 def next ( arr , target ) :
	start = 0 ;
	end = len ( arr ) - 1 ;
	if ( end == 0 ) :
		return - 1 ;
	if ( target > arr [ end ] ) :
		return end ;
	ans = - 1 ;
	while ( start <= end ) :
		mid = ( start + end ) // 2 ;
		if ( arr [ mid ] >= target ) :
			end = mid - 1 ;
		else :
			ans = mid ;
			start = mid + 1 ;
	return ans ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 3 , 5 , 8 , 12 ] ;
	print ( next ( arr , 5 ) ) ;