human
Length of the longest alternating even odd subarray | Function to find the longest subarray.
Length of longest alternating subarray.
Iterate in the array.
Increment count if consecutive elements has an odd sum.
Store maximum count in longest.
Reinitialize cnt as 1 consecutive elements does not have an odd sum.
Length of ' longest ' can never be 1 since even odd has to occur in pair or more so return 0 if longest = 1.
Driver Code"
Solution in Python:
 Give me a code to length of the longest alternating even odd subarray and the other steps required?
assistant
#Here is code to length of the longest alternating even odd subarray and the other steps required.
 def longestEvenOddSubarray ( arr , n ) :
	longest = 1
	cnt = 1
	for i in range ( n - 1 ) :
		if ( ( arr [ i ] + arr [ i + 1 ] ) % 2 == 1 ) :
			cnt = cnt + 1
		else :
			longest = max ( longest , cnt )
			cnt = 1
	if ( longest == 1 ) :
	return 0
	return max ( cnt , longest )
arr = [ 1 , 2 , 3 , 4 , 5 , 7 , 8 ]
n = len ( arr )
print ( longestEvenOddSubarray ( arr , n ) )