human
Find character at Kth index by appending S1 ( M ) times and S2 ( M + 1 ) times | Python program to solve the above approach.
initializing first and second variable as to store how many string ' s ' and string ' t ' will be appended.
storing tmp length.
if length of string tmp is greater than k , then we have reached our destination string now we can return character at index k.
appending s to tmp , f times.
appending t to tmp , s times.
extracting output character.
Driver code"
Solution in Python:
assistant
#Here is code to find character at Kth index by appending S1 ( M ) times and S2 ( M + 1 ) times and the other steps required.
 def KthCharacter ( s , t , k ) :
	f = 1
	ss = 2
	tmp = " "
	lenn = len ( tmp )
	while ( lenn < k ) :
		tf = f
		ts = ss
		while ( tf != 0 ) :
			tf -= 1
			tmp += s
		while ( ts != 0 ) :
			ts -= 1
			tmp += t
		f += 2
		ss += 2
		lenn = len ( tmp )
	output = tmp [ k - 1 ]
	return output
S1 = " a "
S2 = " bc "
k = 4
ans = KthCharacter ( S1 , S2 , k )
print ( ans )