human
Write me a code to minimum number of elements to add to make median equals x and the other steps required given the following:
Minimum number of elements to add to make median equals x | Python3 program to find minimum number of elements to add so that its median equals x ..
no . of elements equals to x , that is , e ..
no . of elements greater than x , that is , h ..
no . of elements smaller than x , that is , l ..
subtract the no . of elements that are equal to x ..
Driver code"
Solution in Python:
assistant
#Here is code to minimum number of elements to add to make median equals x and the other steps required.
 def minNumber ( a , n , x ) :
	l = 0
	h = 0
	e = 0
	for i in range ( n ) :
		if a [ i ] == x :
			e += 1
		elif a [ i ] > x :
			h += 1
		elif a [ i ] < x :
			l += 1
	ans = 0 ;
	if l > h :
		ans = l - h
	elif l < h :
		ans = h - l - 1 ;
	return ans + 1 - e
x = 10
a = [ 10 , 20 , 30 ]
n = len ( a )
print ( minNumber ( a , n , x ) )