human
What is a code to convert given Strings into T by replacing characters in between strings any number of times and the other steps required given the following:
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 T.
Stores the frequency of all the strings in the array arr [ ].
Stores the frequency of the T.
Iterate over the characters of the T.
Iterate in the range [ 0 , N - 1 ].
Iterate over the characters of the 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"
How can the above be solved in Python?
assistant
#Here is code to convert given Strings into T by replacing characters in between strings any number of times and the other steps required.
 def checkIfPossible ( N , arr , T ) :
	freqS = [ 0 ] * 256
	freqT = [ 0 ] * 256
	for ch in T :
		freqT [ ord ( ch ) - ord ( ' a ' ) ] += 1
	for i in range ( N ) :
		for ch in arr [ i ] :
			freqS [ ord ( ch ) - ord ( ' a ' ) ] += 1
	for i in range ( 256 ) :
		if ( freqT [ i ] == 0 and freqS [ i ] != 0 ) :
			return " No "
		elif ( freqS [ i ] == 0 and freqT [ i ] != 0 ) :
			return " No "
		elif ( freqT [ i ] != 0 and freqS [ i ] != ( freqT [ i ] * N ) ) :
			return " No "
	return " Yes "
if __name__ == ' _ _ main _ _ ' :
	arr = [ " abc " , " abb " , " acc " ]
	T = " abc "
	N = len ( arr )
	print ( checkIfPossible ( N , arr , T ) )