human
Check if a triplet of buildings can be selected such that the third building is taller than the first building and smaller than the second building | Function to check if it is possible to select three buildings that satisfy the given condition.
Stores prefix min array.
Iterate over the range [ 1 , N - 1 ].
Stores the element from the ending in increasing order.
Iterate until j is greater than or equal to 0.
If current array element is greater than the prefix min upto j.
Iterate while stack is not empty and top element is less than or equal to preMin [ j ].
Remove the top element.
If stack is not empty and top element of the stack is less than the current element.
Push the arr [ j ] in stack.
If none of the above case satisfy then return " No ".
Driver code.
Input"
Solution in Python:

=====
Write me a code to check if a triplet of buildings can be selected such that the third building is taller than the first building and smaller than the second building and the other steps required?
assistant
#Here is code to check if a triplet of buildings can be selected such that the third building is taller than the first building and smaller than the second building and the other steps required.
 def recreationalSpot ( arr , N ) :
	if ( N < 3 ) :
		return " No "
	preMin = [ 0 ] * N
	preMin [ 0 ] = arr [ 0 ]
	for i in range ( 1 , N ) :
		preMin [ i ] = min ( preMin [ i - 1 ] , arr [ i ] )
	stack = [ ]
	for j in range ( N - 1 , - 1 , - 1 ) :
		if ( arr [ j ] > preMin [ j ] ) :
			while ( len ( stack ) > 0 and stack [ - 1 ] <= preMin [ j ] ) :
				del stack [ - 1 ]
			if ( len ( stack ) > 0 and stack [ - 1 ] < arr [ j ] ) :
				return " Yes "
			stack . append ( arr [ j ] )
	return " No "
if __name__ == ' _ _ main _ _ ' :
	arr = [ 4 , 7 , 11 , 5 , 13 , 2 ]
	size = len ( arr )
	print ( recreationalSpot ( arr , size ) )