human
Check if an array is Wave Array | Function to check if array is wave array arr : input array n : size of array.
Check the wave form If arr [ 1 ] is greater than left and right . Same pattern will be followed by whole elements , else reverse pattern will be followed by array elements.
Check for last element.
Check for last element.
Driver Code.
Array"
How can the above be solved in Python?
 Give me a code to check if an array is Wave Array and the other steps required?
assistant
#Here is code to check if an array is Wave Array and the other steps required.
 def isWaveArray ( arr , n ) :
	result = True
	if ( arr [ 1 ] > arr [ 0 ] and arr [ 1 ] > arr [ 2 ] ) :
		for i in range ( 1 , n - 1 , 2 ) :
			if ( arr [ i ] > arr [ i - 1 ] and arr [ i ] > arr [ i + 1 ] ) :
				result = True
			else :
				result = False
				break
		if ( result == True and n % 2 == 0 ) :
			if ( arr [ n - 1 ] <= arr [ n - 2 ] ) :
				result = False
	elif ( arr [ 1 ] < arr [ 0 ] and arr [ 1 ] < arr [ 2 ] ) :
		for i in range ( 1 , n - 1 , 2 ) :
			if ( arr [ i ] < arr [ i - 1 ] and arr [ i ] < arr [ i + 1 ] ) :
				result = True
			else :
				result = False
				break
		if ( result == True and n % 2 == 0 ) :
			if ( arr [ n - 1 ] >= arr [ n - 2 ] ) :
				result = False
	return result
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 3 , 2 , 4 ]
	n = len ( arr )
	if ( isWaveArray ( arr , n ) ) :
		print ( " YES " )
	else :
		print ( " NO " )