Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS

Starting from the integer 4, 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 79?

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

Correct answer: D. 6

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic