Check if all strings of an array can be made same by interchanging characters | C # program to implement the above approach ; Function to check if all Strings are equal after swap operations ; Stores the frequency of characters ; Stores the length of String ; Traverse the array ; Traverse each String ; Check if frequency of character is divisible by N ; Driver Code
using System ; class GFG { static bool checkEqual ( String [ ] arr , int N ) { int [ ] hash = new int [ 256 ] ; int M = arr [ 0 ] . Length ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { hash [ arr [ i ] [ j ] ] ++ ; } } for ( int i = 0 ; i < 256 ; i ++ ) { if ( hash [ i ] % N != 0 ) { return false ; } } return true ; } public static void Main ( String [ ] args ) { String [ ] arr = { " fdd " , " fhh " } ; int N = arr . Length ; if ( checkEqual ( arr , N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }