Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

Starting from the integer 13, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative integers. What is the minimum number of operations needed to reach exactly 69?

  1. A. 6
  2. B. 56
  3. C. 8
  4. D. 7

Correct answer: D. 7

A BFS over the integers gives 7 operations. Peeling back from 69 with halving-when-even gives 7; using only +1 and doubling (no subtraction) needs 7.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic