human
Find the number of elements X such that X + K also exists in the array | Function to return the count of element x such that x + k also lies in this array.
Key in map will store elements and value will store the frequency of the elements.
Find if i . first + K is present in this map or not.
If we find i . first or key + K in this map then we have to increase in answer the frequency of this element.
Driver code.
array initialisation.
size of array.
initialise k"
Solution in Python:

What is a code to find the number of elements X such that X + K also exists in the array and the other steps required?
assistant
#Here is code to find the number of elements X such that X + K also exists in the array and the other steps required.
 def count_element ( N , K , arr ) :
	mp = dict ( )
	for i in range ( N ) :
		mp [ arr [ i ] ] = mp . get ( arr [ i ] , 0 ) + 1
	answer = 0
	for i in mp :
		if i + K in mp :
			answer += mp [ i ]
	return answer
if __name__ == ' _ _ main _ _ ' :
	arr = [ 3 , 6 , 2 , 8 , 7 , 6 , 5 , 9 ]
	N = len ( arr )
	K = 2
	print ( count_element ( N , K , arr ) )