human
Check if the sum of K least and most frequent array elements are equal or not | Function to compare the sum of K most and least occurrences.
Stores frequency of array element.
Stores the frequencies as indexes and putelements with the frequency in a vector.
Find the frequency.
Insert in the vector.
Stores the count of elements.
Traverse the frequency array.
Find the kleastfreqsum.
If the count is K , break.
Reinitialize the count to zero.
Traverse the frequency.
Find the kmostfreqsum.
If the count is K , break.
Comparing the sum.
Otherwise , return No.
Driver Code"
Solution in Python:

=====
Write me a code to check if the sum of K least and most frequent array elements are equal or not and the other steps required?
assistant
#Here is code to check if the sum of K least and most frequent array elements are equal or not and the other steps required.
 def checkSum ( arr , n , k ) :
	m = { }
	for i in range ( n ) :
		if arr [ i ] in m :
			m [ arr [ i ] ] += 1
		else :
			m [ arr [ i ] ] = 1
	freq = [ [ ] for i in range ( n + 1 ) ]
	for i in range ( n ) :
		f = m [ arr [ i ] ]
		if ( f != - 1 ) :
			freq [ f ] . append ( arr [ i ] )
			m [ arr [ i ] ] = - 1
	count = 0
	kleastfreqsum = 0
	for i in range ( n + 1 ) :
		for x in freq [ i ] :
			kleastfreqsum += x
			count += 1
			if ( count == k ) :
				break
		if ( count == k ) :
			break
	count = 0
	kmostfreqsum = 0
	i = n
	while ( i >= 0 ) :
		for x in freq [ i ] :
			kmostfreqsum += x
			count += 1
			if ( count == k ) :
				break
		i -= 1
		if ( count == k ) :
			break
	if ( kleastfreqsum == kmostfreqsum ) :
		return " Yes "
	return " No "
if __name__ == ' _ _ main _ _ ' :
	arr = [ 3 , 2 , 1 , 2 , 3 , 3 , 4 ]
	N = len ( arr )
	K = 2
	print ( checkSum ( arr , N , K ) )