Count pairs of strings that satisfy the given conditions | Function that returns true if c is vowel ; Function to return the count of required pairs ; For every of the array ; Vector to store the vowels of the current string ; If current character is a vowel ; If current contains vowels ; Create tuple ( first vowel , last vowel , total vowels ) ; v stores the indices for which the given condition satisfies Total valid pairs will be half the size ; Driver code
def is_vowel ( c ) : NEW_LINE INDENT return ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) NEW_LINE DEDENT def count ( s , n ) : NEW_LINE INDENT map = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT vowel = [ ] NEW_LINE for j in range ( len ( s [ i ] ) ) : NEW_LINE INDENT if ( is_vowel ( s [ i ] [ j ] ) ) : NEW_LINE INDENT vowel . append ( s [ i ] [ j ] ) NEW_LINE DEDENT DEDENT if ( len ( vowel ) > 0 ) : NEW_LINE INDENT Len = len ( vowel ) NEW_LINE if ( vowel [ 0 ] , vowel [ Len - 1 ] , Len ) in map . keys ( ) : NEW_LINE INDENT map [ ( vowel [ 0 ] , vowel [ Len - 1 ] , Len ) ] . append ( i ) NEW_LINE DEDENT else : NEW_LINE INDENT map [ ( vowel [ 0 ] , vowel [ Len - 1 ] , Len ) ] = [ i , ] NEW_LINE DEDENT DEDENT DEDENT count = 0 NEW_LINE for i in map : NEW_LINE INDENT v = map [ i ] NEW_LINE count += len ( v ) // 2 NEW_LINE DEDENT return count NEW_LINE DEDENT s = [ " geeks " , " for " , " geeks " ] NEW_LINE n = len ( s ) NEW_LINE print ( count ( s , n ) ) NEW_LINE