human
Elements to be added so that all elements of a range are present in array | Function to count numbers to be added.
Make a hash of elements and store minimum and maximum element.
Traverse all elements from minimum to maximum and count if it is not in the hash.
Driver code"
How can the above be solved in Python?
 What is a code to elements to be added so that all elements of a range are present in array and the other steps required?
assistant
#Here is code to elements to be added so that all elements of a range are present in array and the other steps required.
 def countNum ( arr , n ) :
	s = dict ( )
	count , maxm , minm = 0 , - 10 ** 9 , 10 ** 9
	for i in range ( n ) :
		s [ arr [ i ] ] = 1
		if ( arr [ i ] < minm ) :
			minm = arr [ i ]
		if ( arr [ i ] > maxm ) :
			maxm = arr [ i ]
	for i in range ( minm , maxm + 1 ) :
		if i not in s . keys ( ) :
			count += 1
	return count
arr = [ 3 , 5 , 8 , 6 ]
n = len ( arr )
print ( countNum ( arr , n ) )