Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: Starting from x = 7, apply six times the rule: if x is even, x = x/2 (integer), otherwise x = 2x + 3. What is the final value of x?

  1. A. 317
  2. B. 637
  3. C. 1277
  4. D. 511

Correct answer: B. 637

2x + 3 is always odd, so all six steps use it: 7, 17, 37, 77, 157, 317, 637. Five steps give 317, seven give 1277, and using 2x + 1 gives 511.

More Coding Interview Problems questions

Exams that ask this topic