find the minimum number of operations that will result in N from initial value M?
Attachments:
Answers
Answered by
0
Answer:
Given two integers N and M. The task is to find the minimum number of steps to reach M from N by performing given operations.
Multiply a number x by 2. So, x becomes 2*x.
Subtract one from the number x. So, x becomes x-1.
Examples:
Input : N = 4, M = 6
Output : 2
Explanation : Perform operation number 2 on N.
So, N becomes 3 and then perform operation number 1.
Then, N becomes 6. So, the minimum number of steps is 2.
Input : N = 10, M = 1
Output : 9
Explanation : Perform operation number two
9 times on N. Then N becomes 1.
Explanation:
Similar questions