human
Write me a code to maximize product of lengths of strings having no common characters and the other steps required given the following:
Maximize product of lengths of strings having no common characters | Function to count the number of set bits in the integer n.
Stores the count of set bits in n.
Return the count.
Function to find the maximum product of pair of strings having no common characters.
Stores the integer equivalent of the strings.
Traverse the array of strings.
Traverse the current string.
Store the current bit position in bits [ i ].
Store the required result.
Traverse the array , bits [ ] to get all unique pairs ( i , j ).
Check whether the strings have no common characters.
Update the overall maximum product.
Print the maximum product.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to maximize product of lengths of strings having no common characters and the other steps required.
 def countSetBits ( n ) :
	count = 0
	while ( n > 0 ) :
		count += n & 1
		n >>= 1
	return count
def maximumProduct ( words ) :
	bits = [ 0 for i in range ( len ( words ) ) ]
	for i in range ( len ( words ) ) :
		for j in range ( len ( words [ i ] ) ) :
			bits [ i ] = bits [ i ] | 1 << ( ord ( words [ i ] [ j ] ) - 97 )
	result = 0
	for i in range ( len ( bits ) ) :
		for j in range ( i + 1 , len ( bits ) ) :
			if ( ( bits [ i ] & bits [ j ] ) == 0 ) :
				L = countSetBits ( bits [ i ] )
				R = countSetBits ( bits [ j ] )
				result = max ( L * R , result )
	print ( result )
if __name__ == ' _ _ main _ _ ' :
	arr = [ " abcw " , " baz " , " foo " , " bar " , " xtfn " , " abcdef " ]
	maximumProduct ( arr )