human
Find the amplitude and number of waves for the given array | Function to find the amplitude and number of waves for the given array.
Check for both sides adjacent elements that both must be less or both must be greater than current element.
Update amplitude with max value.
Prthe Amplitude.
Driver Code.
Given array a [ ].
Calculate number of waves.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to find the amplitude and number of waves for the given array and the other steps required.
 def check ( a , n ) :
	ma = a [ 1 ] - a [ 0 ]
	for i in range ( 1 , n - 1 ) :
		if ( ( a [ i ] > a [ i - 1 ] and a [ i + 1 ] < a [ i ] ) or ( a [ i ] < a [ i - 1 ] and a [ i + 1 ] > a [ i ] ) ) :
			ma = max ( ma , abs ( a [ i ] - a [ i + 1 ] ) )
		else :
			return False
	print ( " Amplitude ▁ = ▁ " , ma )
	return True
if __name__ == ' _ _ main _ _ ' :
	a = [ 1 , 2 , 1 , 5 , 0 , 7 , - 6 ]
	n = len ( a )
	wave = ( n - 1 ) // 2
	if ( check ( a , n ) ) :
		print ( " Waves ▁ = ▁ " , wave )
	else :
		print ( " - 1" )