Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: The Collatz sequence starts at n = 27 and repeatedly applies: n → n/2 if n is even, n → 3n+1 if n is odd, until n = 1. How many steps does it take to reach 1?

  1. A. 112
  2. B. 9232
  3. C. 111
  4. D. 41

Correct answer: C. 111

Simulating 27 → 82 → 41 → … → 1 takes 111 steps (it climbs as high as 9232 on the way). Counting the terms including 27 gives 112, 9232 is the peak value rather than a step count, and counting only the 3n + 1 steps gives 41.

More Coding Interview Problems questions

Exams that ask this topic