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

1 Expert Approved Answer
Step: 1 Unlock

Algorithm Initialize an array steps to keep track of the number of steps required to reach each valu... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Data Structures Algorithms Questions!