Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional

Starting from the integer 14, 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 159?

  1. A. 145
  2. B. 11
  3. C. 10
  4. D. 9

Correct answer: D. 9

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic