human
Can you provide a code to check if a string is made up of K alternating characters and the other steps required given the following:
Check if a string is made up of K alternating characters | Function to check if a string is made up of k alternating characters.
Check if all the characters at indices 0 to K - 1 are different.
If that bit is already set in checker , return false.
Otherwise update and continue by setting that bit in the checker.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to check if a string is made up of K alternating characters and the other steps required.
 def isKAlternating ( s , k ) :
	if ( len ( s ) < k ) :
		return False
	checker = 0
	for i in range ( k ) :
		bitAtIndex = ord ( s [ i ] ) - ord ( ' a ' )
		if ( ( checker & ( 1 << bitAtIndex ) ) > 0 ) :
			return False
		checker = checker | ( 1 << bitAtIndex )
	for i in range ( k , len ( s ) ) :
		if ( s [ i - k ] != s [ i ] ) :
			return False
	return True
if __name__ == " _ _ main _ _ " :
	st = " acdeac "
	K = 4
	if ( isKAlternating ( st , K ) ) :
		print ( " Yes " )
	else :
		print ( " No " )