text: Convert given Strings into T by replacing characters in between strings any number of times | Function to check if it possible to make all the strings equal to the string T ; Stores the frequency of all the strings in the array arr [ ] ; Stores the frequency of the string T ; Iterate over the characters of the string T ; Iterate in the range [ 0 , N - 1 ] ; Iterate over the characters of the string arr [ i ] ; If freqT [ i ] is 0 and freqS [ i ] is not 0 ; If freqS [ i ] is 0 and freqT [ i ] is not 0 ; If freqS [ i ] is not freqT [ i ] * N ; Otherwise , return " Yes " ; Driver Code
code: function checkIfPossible ( N , arr , T ) { let freqS = new Array ( 256 ) . fill ( 0 ) ; let freqT = new Array ( 256 ) . fill ( 0 ) ; for ( let ch of T ) { freqT [ ch . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } for ( let i = 0 ; i < N ; i ++ ) { for ( let ch of arr [ i ] ) { freqS [ ch . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } } for ( let i = 0 ; i < 256 ; i ++ ) { if ( freqT [ i ] == 0 && freqS [ i ] != 0 ) { return " " ; } else if ( freqS [ i ] == 0 && freqT [ i ] != 0 ) { return " " ; } else if ( freqT [ i ] != 0 && freqS [ i ] != ( freqT [ i ] * N ) ) { return " " ; } } return " " ; } let arr = [ " " , " " , " " ] ; let T = " " ; let N = arr . length ; document . write ( checkIfPossible ( N , arr , T ) ) ;