human
Write me a code to convert to a string that is repetition of a substring of k length and the other steps required given the following:
Convert to a string that is repetition of a substring of k length | Returns True if S can be converted to a with k repeated subs after replacing k characters ..
Length of must be a multiple of k.
Map to store s of length k and their counts.
If is already a repetition of k subs , return True ..
If number of distinct subs is not 2 , then not possible to replace a ..
One of the two distinct must appear exactly once . Either the first entry appears once , or it appears n / k - 1 times to make other sub appear once ..
Driver code"
Solution in Python:
assistant
#Here is code to convert to a string that is repetition of a substring of k length and the other steps required.
 def check ( S , k ) :
	n = len ( S )
	if ( n % k != 0 ) :
		return False
	mp = { }
	for i in range ( 0 , n , k ) :
		mp [ S [ i : k ] ] = mp . get ( S [ i : k ] , 0 ) + 1
	if ( len ( mp ) == 1 ) :
		return True
	if ( len ( mp ) != 2 ) :
		return False
	for i in mp :
		if i == ( n // k - 1 ) or mp [ i ] == 1 :
			return True
	return False
if check ( " abababcd " , 2 ) :
	print ( " Yes " )
else :
	print ( " No " )