human
Give me a code to sum of array elements whose count of set bits are unique and the other steps required given the following:
Sum of array elements whose count of set bits are unique | Function to count the number of set bits in an integer N.
Stores the count of set bits.
Iterate until N is non - zero.
Stores the resultant count.
Function to calculate sum of all array elements whose count of set bits are unique.
Stores frequency of all possible count of set bits.
Stores the sum of array elements.
Traverse the array.
Count the number of set bits.
Traverse the array and Update the value of ans.
If frequency is 1.
Driver Code"
Solution in Python:
assistant
#Here is code to sum of array elements whose count of set bits are unique and the other steps required.
 def setBitCount ( n ) :
	ans = 0
	while n :
		ans += n & 1
		n >>= 1
	return ans
def getSum ( arr ) :
	mp = { }
	ans = 0
	for i in arr :
		key = setBitCount ( i )
		mp [ key ] = [ 0 , i ]
	for i in arr :
		key = setBitCount ( i )
		mp [ key ] [ 0 ] += 1
	for i in mp :
		if mp [ i ] [ 0 ] == 1 :
			ans += mp [ i ] [ 1 ]
	print ( ans )
arr = [ 8 , 3 , 7 , 5 , 3 ]
getSum ( arr )