Arrangement of words without changing the relative position of vowel and consonants | this function return n ! ; this will return total number of ways ; freq maintains frequency of each character in word ; check character is vowel or not ; the characters that are not vowel must be consonant ; number of ways to arrange vowel ; multiply both as these are independent ; string contains only capital letters ; this will contain ans
function factorial ( n ) { let res = 1 ; for ( let i = 1 ; i <= n ; i ++ ) res = res * i ; return res ; } function count1 ( word ) { let freq = new Array ( 27 ) . fill ( 0 ) ; for ( let i = 0 ; i < 27 ; i ++ ) freq [ i ] = 0 ; let vowel = 0 ; let consonant = 0 ; for ( let i = 0 ; i < word . length ; i ++ ) { freq [ word . charCodeAt ( i ) - 65 ] ++ ; if ( word [ i ] == ' ' word [ i ] == ' ' word [ i ] == ' ' word [ i ] == ' ' word [ i ] == ' ' ) { vowel ++ ; } else consonant ++ ; } vowelArrange = factorial ( vowel ) ; vowelArrange /= factorial ( freq [ 0 ] ) ; vowelArrange /= factorial ( freq [ 4 ] ) ; vowelArrange /= factorial ( freq [ 8 ] ) ; vowelArrange /= factorial ( freq [ 14 ] ) ; vowelArrange /= factorial ( freq [ 20 ] ) ; consonantArrange = factorial ( consonant ) ; for ( let i = 0 ; i < 26 ; i ++ ) { if ( i != 0 && i != 4 && i != 8 && i != 14 && i != 20 ) consonantArrange /= factorial ( freq [ i ] ) ; } let total = vowelArrange * consonantArrange ; return total ; } let word = " " ; let ans = count1 ( word ) ; document . write ( ans ) ;