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 ; Function call
function good_pairs ( str , N ) { let arr = new Array ( 32 ) ; arr . fill ( 0 ) ; let strCount = 0 ; for ( let i = 0 ; i < N ; i ++ ) { let Weight = 0 ; for ( let j = 0 ; j < str [ i ] . length ; j ++ ) { switch ( str [ i ] [ j ] ) { case ' ' : Weight = Weight | 1 ; break ; case ' ' : Weight = Weight | 2 ; break ; case ' ' : Weight = Weight | 4 ; break ; case ' ' : Weight = Weight | 8 ; break ; case ' ' : Weight = Weight | 16 ; break ; } } arr [ Weight ] ++ ; } for ( let i = 0 ; i < 32 ; i ++ ) { for ( let j = i + 1 ; j < 32 ; j ++ ) { if ( ( i j ) == 31 ) strCount += arr [ i ] * arr [ j ] ; } } strCount += parseInt ( ( arr [ 31 ] * ( arr [ 31 ] - 1 ) ) / 2 , 10 ) ; return strCount ; } let str = [ " " , " " ] ; let N = str . length ; document . write ( good_pairs ( str , N ) ) ;