Make all strings from a given array equal by replacing minimum number of characters | 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
function minOperation ( arr , N ) { var cntMinOP = 0 ; var M = arr [ 0 ] . length ; var hash = Array . from ( Array ( 256 ) , ( ) => Array ( M ) . fill ( 0 ) ) ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < M ; j ++ ) { hash [ arr [ i ] [ j ] . charCodeAt ( 0 ) ] [ j ] ++ ; } } for ( var i = 0 ; i < M ; i ++ ) { var Sum = 0 ; var Max = 0 ; for ( var j = 0 ; j < 256 ; j ++ ) { Sum += hash [ j ] [ i ] ; Max = Math . max ( Max , hash [ j ] [ i ] ) ; } cntMinOP += ( Sum - Max ) ; } return cntMinOP ; } var arr = [ " " , " " , " " ] ; var N = arr . length ; document . write ( minOperation ( arr , N ) + " " ) ;