Data Structures & AlgorithmsHardGATE CS · TCS NQT

Starting from n = 100, repeat: if n is divisible by 3, divide it by 3; otherwise subtract 1. How many steps are needed to reach 1?

  1. A. 8
  2. B. 9
  3. C. 11
  4. D. 7

Correct answer: D. 7

Count each operation. The path is 100, 99, 33, 11, 10, 9, 3, 1, which takes 7 operations.

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

Exams that ask this topic