human
Give me a code to minimize steps to reach K from 0 by adding 1 or doubling at each step and the other steps required given the following:
Minimize steps to reach K from 0 by adding 1 or doubling at each step | Function to find minimum operations.
dp is initialised to store the steps.
For all even numbers.
Driver Code"
Solution in Python:
assistant
#Here is code to minimize steps to reach K from 0 by adding 1 or doubling at each step and the other steps required.
 def minOperation ( k ) :
	dp = [ 0 ] * ( k + 1 )
	for i in range ( 1 , k + 1 ) :
		dp [ i ] = dp [ i - 1 ] + 1
		if ( i % 2 == 0 ) :
			dp [ i ] = min ( dp [ i ] , dp [ i // 2 ] + 1 )
	return dp [ k ]
if __name__ == ' _ _ main _ _ ' :
	k = 12
	print ( minOperation ( k ) )