Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional

Starting from the integer 6, 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 158?

  1. A. 7
  2. B. 152
  3. C. 10
  4. D. 8

Correct answer: A. 7

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic