human
Write me a code to find Kth element in an array containing odd elements first and then even elements and the other steps required given the following:
Find Kth element in an array containing odd elements first and then even elements | Function to return the kth element in the modified array.
First odd number.
Insert the odd number.
Next odd number.
First even number.
Insert the even number.
Next even number.
Return the kth element.
Driver code"
Solution in Python:
assistant
#Here is code to find Kth element in an array containing odd elements first and then even elements and the other steps required.
 def getNumber ( n , k ) :
	arr = [ 0 ] * n ;
	i = 0 ;
	odd = 1 ;
	while ( odd <= n ) :
		arr [ i ] = odd ;
		i += 1 ;
		odd += 2 ;
	even = 2 ;
	while ( even <= n ) :
		arr [ i ] = even ;
		i += 1 ;
		even += 2 ;
	return arr [ k - 1 ] ;
if __name__ == ' _ _ main _ _ ' :
	n = 8 ;
	k = 5 ;
	print ( getNumber ( n , k ) ) ;