Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Start at 1 and apply the rules: multiply by 3 if the number is even, add 5 if it is odd. Apply 9 steps. What is the final value?

  1. A. 13122
  2. B. 118098
  3. C. 39366
  4. D. 19683

Correct answer: C. 39366

1 is odd so it becomes 6; from then on every value is even and is tripled, so after 9 steps the value is 6 · 3⁸ = 39366. Stopping after 8 steps gives 13122, doing 10 steps gives 118098, and swapping the rules (×3 when odd) gives 3⁹ = 19683.

More Coding Interview Problems questions

Exams that ask this topic