Data Structures & AlgorithmsVery hardCodeforces Div2 C · GATE CS

Starting from the number 1, each operation either doubles the current number or adds 1. What is the minimum number of operations needed to reach exactly 100?

  1. A. 99
  2. B. 6
  3. C. 3
  4. D. 8

Correct answer: D. 8

Work backwards from 100 (1100100₂): halve when even, subtract 1 when odd: 100 → 50 → 25 → 24 → 12 → 6 → 3 → 2 → 1, i.e. 8 operations (6 doublings + 2 additions). 6 counts only doublings, 3 is the popcount, and 99 uses only +1.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic