Count ways to place all the characters of two given strings alternately | C # program to implement the above approach ; 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
using System ; class GFG { static int fact ( int n ) { int res = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { res = res * i ; } return res ; } static int distinctWays ( string str1 , string str2 ) { int n = str1 . Length ; int m = str2 . Length ; if ( n == m ) { return 2 * fact ( n ) * fact ( m ) ; } return fact ( n ) * fact ( m ) ; } public static void Main ( ) { string str1 = " aegh " ; string str2 = " rsw " ; Console . Write ( distinctWays ( str1 , str2 ) ) ; } }