Count of distinct Strings possible by swapping prefixes of pairs of Strings from the Array | C # Program to implement the above approach ; Function to count the distinct strings possible after swapping the prefixes between two possible strings of the array ; Stores the count of unique characters for each index ; Store current string ; Stores the total number of distinct strings possible ; Return the answer ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int mod = 1000000007 ; public static long countS ( String [ ] str , int n , int m ) { Dictionary < int , HashSet < char > > counts = new Dictionary < int , HashSet < char > > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { counts . Add ( i , new HashSet < char > ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { String s = str [ i ] ; for ( int j = 0 ; j < m ; j ++ ) { counts [ j ] . Add ( s [ j ] ) ; } } long result = 1 ; foreach ( int index in counts . Keys ) result = ( result * counts [ index ] . Count ) % mod ; return result ; } public static void Main ( String [ ] args ) { String [ ] str = { "112" , "211" } ; int N = 2 , M = 3 ; Console . WriteLine ( countS ( str , N , M ) ) ; } }