Count pair of strings whose concatenation has every vowel | Java program for the above approach ; 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 ; Driver code ; Given array of strings ; Function call
class GFG { public static int good_pairs ( String [ ] str , int N ) { int arr [ ] = new int [ 32 ] ; int strCount = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int Weight = 0 ; for ( int j = 0 ; j < str [ i ] . length ( ) ; j ++ ) { switch ( str [ i ] . charAt ( j ) ) { case ' a ' : Weight = Weight | 1 ; break ; case ' e ' : Weight = Weight | 2 ; break ; case ' i ' : Weight = Weight | 4 ; break ; case ' o ' : Weight = Weight | 8 ; break ; case ' u ' : Weight = Weight | 16 ; break ; } } arr [ Weight ] ++ ; } for ( int i = 0 ; i < 32 ; i ++ ) { for ( int j = i + 1 ; j < 32 ; j ++ ) { if ( ( i j ) == 31 ) strCount += arr [ i ] * arr [ j ] ; } } strCount += ( arr [ 31 ] * ( arr [ 31 ] - 1 ) ) / 2 ; return strCount ; } public static void main ( String [ ] args ) { String str [ ] = { " aaweiolkju " , " oxdfgujkmi " } ; int N = str . length ; System . out . println ( good_pairs ( str , N ) ) ; } }