human
Can you provide a code to total character pairs from two strings , with equal number of set bits in their ascii value and the other steps required given the following:
Total character pairs from two strings , with equal number of set bits in their ascii value | Function to get no of set bits in binary representation of positive integer n.
Function to return the count of valid pairs.
Store frequency of number of set bits for s1.
Store frequency of number of set bits for s2.
Calculate total pairs.
Return the count of valid pairs.
Driver code"
Solution in Python:
assistant
#Here is code to total character pairs from two strings , with equal number of set bits in their ascii value and the other steps required.
 def countSetBits ( n ) :
	count = 0
	while ( n ) :
		count += n & 1
		n >>= 1
	return count
def totalPairs ( s1 , s2 ) :
	count = 0 ;
	arr1 = [ 0 ] * 7 ; arr2 = [ 0 ] * 7 ;
	for i in range ( len ( s1 ) ) :
		set_bits = countSetBits ( ord ( s1 [ i ] ) )
		arr1 [ set_bits ] += 1 ;
	for i in range ( len ( s2 ) ) :
		set_bits = countSetBits ( ord ( s2 [ i ] ) ) ;
		arr2 [ set_bits ] += 1 ;
	for i in range ( 1 , 7 ) :
		count += ( arr1 [ i ] * arr2 [ i ] ) ;
	return count ;
if __name__ == " _ _ main _ _ " :
	s1 = " geeks " ;
	s2 = " forgeeks " ;
	print ( totalPairs ( s1 , s2 ) ) ;