Computer Science, asked by FarahJamal, 15 days ago

find the minimum number of operations that will result in N from initial value M?

Answers

Answered by anjaliitkalkar
1

Answer:

had an interview and couldn't think a clear/best solution for this problem.

Given 2 numbers A and B and we need to convert a number A to B with minimum number of the following operations:

Subtract 1

Add 1

Multiply 2

Divide 2

Multiply 3

Divide 3

For e.g. : if a=3 and b=7, the program should output 2.

1st operation : *2 -> 3*2 = 6.

2nd operation : +1 -> 6 + 1 =7.

For e.g. : if a=10 and b=60, the program should output 2.

1st operation: *2 -> 10*2 = 20.

2nd operation: *3 -> 20*3 = 60

As we can Change m (10) to n (60) after 2 operations, the answer is 2.

Answered by atam52
1

Answer:

a=3 and b=7, the program should output 2.

1st operation : *2 -> 3*2 = 6.

2nd operation : +1 -> 6 + 1 =7.

For e.g. : if a=10 and b=60, the program should output 2.

1st operation: *2 -> 10*2 = 20.

2nd operation: *3 -> 20*3 = 60

As we can Change m (10) to n (60) after 2 operations, the answer is 2.

mark me brilliant plz

Similar questions