human
Number of anomalies in an array | Python3 program to implement the above approach.
Sort the array so that we can apply binary search ..
One by one check every element if it is anomaly or not using binary search ..
If arr [ i ] is not largest element and element just greater than it is within k , then return False ..
If there are more than one occurrences of arr [ i ] , return False ..
If arr [ i ] is not smallest element and just smaller element is not k distance away.
Driver code"
Solution in Python:

What is a code to number of anomalies in an array and the other steps required?
assistant
#Here is code to number of anomalies in an array and the other steps required.
 def countAnomalies ( a , n , k ) :
	a = sorted ( a ) ;
	res = 0 ;
	for i in range ( n ) :
		u = upper_bound ( a , 0 , n , a [ i ] ) ;
		if ( u < n and a [ u ] - a [ i ] <= k ) :
			continue ;
		s = lower_bound ( a , 0 , n , a [ i ] ) ;
		if ( u - s > 1 ) :
			continue ;
		if ( s > 0 and a [ s - 1 ] - a [ i ] <= k ) :
			continue ;
		res += 1 ;
	return res ;
def lower_bound ( a , low , high , element ) :
	while ( low < high ) :
		middle = int ( low + int ( high - low ) / 2 ) ;
		if ( element > a [ middle ] ) :
			low = middle + 1 ;
		else :
			high = middle ;
	return low ;
def upper_bound ( a , low , high , element ) :
	while ( low < high ) :
		middle = int ( low + ( high - low ) / 2 ) ;
		if ( a [ middle ] > element ) :
			high = middle ;
		else :
			low = middle + 1 ;
	return low ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 7 , 1 , 8 ]
	k = 5 ;
	n = len ( arr ) ;
	print ( countAnomalies ( arr , n , k ) ) ;