Count number of rotated strings which have more number of vowels in the first half than second half | Function to return the count of rotated strings which have more number of vowels in the first half than the second half ; Compute the number of vowels in first - half ; Compute the number of vowels in second - half ; Check if first - half has more vowels ; Check for all possible rotations ; Return the answer ; Driver code ; Function call
function cntRotations ( s , n ) { let lh = 0 , rh = 0 , i , ans = 0 ; for ( i = 0 ; i < parseInt ( n / 2 , 10 ) ; ++ i ) if ( s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' ) { lh ++ ; } for ( i = parseInt ( n / 2 , 10 ) ; i < n ; ++ i ) if ( s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' s [ i ] == ' ' ) { rh ++ ; } if ( lh > rh ) ans ++ ; for ( i = 1 ; i < n ; ++ i ) { if ( s [ i - 1 ] == ' ' s [ i - 1 ] == ' ' s [ i - 1 ] == ' ' s [ i - 1 ] == ' ' s [ i - 1 ] == ' ' ) { rh ++ ; lh -- ; } if ( s [ ( i - 1 + n / 2 ) % n ] == ' ' || s [ ( i - 1 + n / 2 ) % n ] == ' ' || s [ ( i - 1 + n / 2 ) % n ] == ' ' || s [ ( i - 1 + n / 2 ) % n ] == ' ' || s [ ( i - 1 + n / 2 ) % n ] == ' ' ) { rh -- ; lh ++ ; } if ( lh > rh ) ans ++ ; } return ans ; } let s = [ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' ] ; let n = s . length ; document . write ( cntRotations ( s , n ) ) ;