human
What is a code to floor of every element in same array and the other steps required given the following:
Floor of every element in same array | Prints greater elements on left side of every element.
Create a sorted copy of arr.
Traverse through arr [ ] and do binary search for every element ..
Floor of first element is - 1 if there is only one occurrence of it ..
Find the first element that is greater than or or equal to given element.
If next element is also same , then there are multiple occurrences , so print it.
Otherwise print previous element.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to floor of every element in same array and the other steps required.
 def printPrevGreater ( arr , n ) :
	v = arr . copy ( )
	v . sort ( )
	for i in range ( n ) :
		if ( arr [ i ] == v [ 0 ] ) :
			if ( arr [ i ] == v [ 1 ] ) :
				print ( arr [ i ] , end = " ▁ " )
			else :
				print ( - 1 , end = " ▁ " )
			continue
		if v . count ( arr [ i ] ) > 0 :
			it = v [ v . index ( arr [ i ] ) ]
		else :
			it = v [ n - 1 ]
		if ( it != v [ n - 1 ] and v [ v . index ( it ) + 1 ] == arr [ i ] ) :
			print ( arr [ i ] , end = " ▁ " )
		else :
			print ( v [ v . index ( it ) - 1 ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 6 , 11 , 7 , 8 , 20 , 12 ]
	n = len ( arr )
	printPrevGreater ( arr , n )