Question: Given two values X and Y. You need to convert X to Y by performing various steps. In a step, we can either multiply 2
Given two values X and Y. You need to convert X to Y by performing various steps. In a step, we can either multiply 2 to the value or subtract 1 from it. You need to display the number of steps and the path. To reach 3 from 1, the path will be [1, 2, 4, 3] and number of steps will be 3.
Create an array to keep track of the number of steps and another array to keep track of parent value.
Step by Step Solution
3.34 Rating (157 Votes )
There are 3 Steps involved in it
Algorithm Initialize an array steps to keep track of the number of steps required to reach each valu... View full answer
Get step-by-step solutions from verified subject matter experts
