human
Given a string and an integer k , find the kth sub | Function to prints kth sub - string.
Total sub - strings possible.
If k is greater than total number of sub - strings.
To store number of sub - strings starting with ith character of the string.
Compute the values.
substring [ i - 1 ] is added to store the cumulative sum.
Binary search to find the starting index of the kth sub - string.
To store the ending index of the kth sub - string.
Print the sub - string.
Driver code"
Solution in Python:
assistant
#Here is code to given a string and an integer k , find the kth sub and the other steps required.
 def Printksubstring ( str1 , n , k ) :
	total = int ( ( n * ( n + 1 ) ) / 2 )
	if ( k > total ) :
		print ( " - 1" )
		return
	substring = [ 0 for i in range ( n + 1 ) ]
	substring [ 0 ] = 0
	temp = n
	for i in range ( 1 , n + 1 , 1 ) :
		substring [ i ] = substring [ i - 1 ] + temp
		temp -= 1
	l = 1
	h = n
	start = 0
	while ( l <= h ) :
		m = int ( ( l + h ) / 2 )
		if ( substring [ m ] > k ) :
			start = m
			h = m - 1
		elif ( substring [ m ] < k ) :
			l = m + 1
		else :
			start = m
			break
	end = n - ( substring [ start ] - k )
	for i in range ( start - 1 , end ) :
		print ( str1 [ i ] , end = " " )
if __name__ == ' _ _ main _ _ ' :
	str1 = " abc "
	k = 4
	n = len ( str1 )
	Printksubstring ( str1 , n , k )