Count ways to place all the characters of two given strings alternately | Function to get the factorial of N ; Function to get the total number of distinct ways ; Length of str1 ; Length of str2 ; If both strings have equal length ; If both strings do not have equal length ; Driver code
function fact ( n ) { var res = 1 ; for ( i = 1 ; i <= n ; i ++ ) { res = res * i ; } return res ; } function distinctWays ( str1 , str2 ) { var n = str1 . length ; var m = str2 . length ; if ( n == m ) { return 2 * fact ( n ) * fact ( m ) ; } return fact ( n ) * fact ( m ) ; } var str1 = " " ; var str2 = " " ; document . write ( distinctWays ( str1 , str2 ) ) ;