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
def fact ( n ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT res = res * i NEW_LINE DEDENT return res NEW_LINE DEDENT def distinctWays ( str1 , str2 ) : NEW_LINE INDENT n = len ( str1 ) NEW_LINE m = len ( str2 ) NEW_LINE if ( n == m ) : NEW_LINE INDENT return 2 * fact ( n ) * fact ( m ) NEW_LINE DEDENT return fact ( n ) * fact ( m ) NEW_LINE DEDENT str1 = " aegh " NEW_LINE str2 = " rsw " NEW_LINE print ( distinctWays ( str1 , str2 ) ) NEW_LINE