Make all strings from a given array equal by replacing minimum number of characters | C # program to implement the above approach ; Function to find the minimum count of operations required to make all Strings equal by replacing characters of Strings ; Stores minimum count of operations required to make all Strings equal ; Stores length of the String ; hash [ i , j ] : Stores frequency of character i present at j - th index of all Strings ; Traverse the array [ ] arr ; Iterate over characters of current String ; Update frequency of arr [ i , j ] ; Traverse hash [ , ] array ; Stores sum of i - th column ; Stores the largest element of i - th column ; Iterate over all possible characters ; Update Sum ; Update Max ; Update cntMinOP ; Driver Code ; Function call
using System ; class GFG { static int minOperation ( String [ ] arr , int N ) { int cntMinOP = 0 ; int M = arr [ 0 ] . Length ; int [ , ] hash = new int [ 256 , M ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { hash [ arr [ i ] [ j ] , j ] ++ ; } } for ( int i = 0 ; i < M ; i ++ ) { int Sum = 0 ; int Max = 0 ; for ( int j = 0 ; j < 256 ; j ++ ) { Sum += hash [ j , i ] ; Max = Math . Max ( Max , hash [ j , i ] ) ; } cntMinOP += ( Sum - Max ) ; } return cntMinOP ; } public static void Main ( String [ ] args ) { String [ ] arr = { " abcd " , " bcde " , " cdef " } ; int N = arr . Length ; Console . Write ( minOperation ( arr , N ) + " STRNEWLINE " ) ; } }