human
Find whether a subarray is in form of a mountain or not | Utility method to construct left and right array.
initialize first left index as that index only.
if current value is greater than previous , update last increasing.
initialize last right index as that index only.
if current value is greater than next , update first decreasing.
method returns true if arr [ L . . R ] is in mountain form.
return true only if right at starting range is greater than left at ending range.
Driver code"
Solution in Python:
 ... Give me a code to find whether a subarray is in form of a mountain or not and the other steps required?
assistant
#Here is code to find whether a subarray is in form of a mountain or not and the other steps required.
 def preprocess ( arr , N , left , right ) :
	left [ 0 ] = 0
	lastIncr = 0
	for i in range ( 1 , N ) :
		if ( arr [ i ] > arr [ i - 1 ] ) :
			lastIncr = i
		left [ i ] = lastIncr
	right [ N - 1 ] = N - 1
	firstDecr = N - 1
	i = N - 2
	while ( i >= 0 ) :
		if ( arr [ i ] > arr [ i + 1 ] ) :
			firstDecr = i
		right [ i ] = firstDecr
		i -= 1
def isSubarrayMountainForm ( arr , left , right , L , R ) :
	return ( right [ L ] >= left [ R ] )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 3 , 2 , 4 , 4 , 6 , 3 , 2 ]
	N = len ( arr )
	left = [ 0 for i in range ( N ) ]
	right = [ 0 for i in range ( N ) ]
	preprocess ( arr , N , left , right )
	L = 0
	R = 2
	if ( isSubarrayMountainForm ( arr , left , right , L , R ) ) :
		print ( " Subarray ▁ is ▁ in ▁ mountain ▁ form " )
	else :
		print ( " Subarray ▁ is ▁ not ▁ in ▁ mountain ▁ form " )
	L = 1
	R = 3
	if ( isSubarrayMountainForm ( arr , left , right , L , R ) ) :
		print ( " Subarray ▁ is ▁ in ▁ mountain ▁ form " )
	else :
		print ( " Subarray ▁ is ▁ not ▁ in ▁ mountain ▁ form " )