human
Previous greater element | Python 3 program previous greater element A naive solution to print previous greater element for every element in an array ..
Previous greater for first element never exists , so we print - 1..
Let us process remaining elements ..
Find first element on left side that is greater than arr [ i ] ..
If all elements on left are smaller ..
Driver code"
Solution in Python:
 Write me a code to previous greater element and the other steps required?
assistant
#Here is code to previous greater element and the other steps required.
 def prevGreater ( arr , n ) :
	print ( " - 1" , end = " , ▁ " )
	for i in range ( 1 , n ) :
		flag = 0
		for j in range ( i - 1 , - 1 , - 1 ) :
			if arr [ i ] < arr [ j ] :
				print ( arr [ j ] , end = " , ▁ " )
				flag = 1
				break
		if j == 0 and flag == 0 :
			print ( " - 1" , end = " , ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 10 , 4 , 2 , 20 , 40 , 12 , 30 ]
	n = len ( arr )
	prevGreater ( arr , n )