Check if all strings of an array can be made same by interchanging characters | 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
function checkEqual ( arr , N ) { var hash = Array ( 256 ) . fill ( 0 ) ; var M = arr [ 0 ] . length ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < M ; j ++ ) { hash [ arr [ i ] [ j ] ] ++ ; } } for ( var i = 0 ; i < 256 ; i ++ ) { if ( hash [ i ] % N != 0 ) { return false ; } } return true ; } var arr = [ " " , " " ] ; var N = arr . length ; if ( checkEqual ( arr , N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }