Count pair of strings whose concatenation has every vowel | Function to return the count of all concatenated string with each vowel at least once ; Creating a hash array with initial value as 0 ; Traversing through each string and getting hash value for each of them ; Initializing the weight of each string ; Find the hash value for each string ; Increasing the count of the hash value ; Getting all possible pairs of indexes in hash array ; Check if the pair which has hash value 31 and multiplying the count of string and add it strCount ; Corner case , for strings which independently has all the vowels ; Return thre final count ; Given array of strings ;
def good_pairs ( Str , N ) : NEW_LINE INDENT arr = [ 0 for i in range ( 32 ) ] NEW_LINE strCount = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT Weight = 0 NEW_LINE for j in range ( len ( Str [ i ] ) ) : NEW_LINE INDENT switcher = { ' a ' : 1 , ' e ' : 2 , ' i ' : 4 , ' o ' : 8 , ' u ' : 16 , } NEW_LINE Weight = Weight | switcher . get ( Str [ i ] [ j ] , 0 ) NEW_LINE DEDENT arr [ Weight ] += 1 NEW_LINE DEDENT for i in range ( 32 ) : NEW_LINE INDENT for j in range ( i + 1 , 32 ) : NEW_LINE INDENT if ( ( i j ) == 31 ) : NEW_LINE INDENT strCount += arr [ i ] * arr [ j ] NEW_LINE DEDENT DEDENT DEDENT strCount += int ( ( arr [ 31 ] * ( arr [ 31 ] - 1 ) ) / 2 ) NEW_LINE return strCount NEW_LINE DEDENT Str = [ " aaweiolkju " , " oxdfgujkmi " ] NEW_LINE N = len ( Str ) NEW_LINE / * Function call * / NEW_LINE print ( good_pairs ( Str , N ) ) NEW_LINE