human
Count number of elements between two given elements in array | Function to count number of elements occurs between the elements ..
Find num1.
If num1 is not present or present at end.
Find num2.
If num2 is not present.
return number of elements between the two elements ..
Driver Code"
Solution in Python:
assistant
#Here is code to count number of elements between two given elements in array and the other steps required.
 def getCount ( arr , n , num1 , num2 ) :
	for i in range ( 0 , n ) :
		if ( arr [ i ] == num1 ) :
			break
	if ( i >= n - 1 ) :
		return 0
	for j in range ( n - 1 , i + 1 , - 1 ) :
		if ( arr [ j ] == num2 ) :
			break
	if ( j == i ) :
		return 0
	return ( j - i - 1 )
arr = [ 3 , 5 , 7 , 6 , 4 , 9 , 12 , 4 , 8 ]
n = len ( arr )
num1 = 5
num2 = 4
print ( getCount ( arr , n , num1 , num2 ) )