Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The sequence a1 = 2, and each next term is a(n+1) = (a(n) × 3 + 1) mod 11. What is a(20)?

  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 6

Correct answer: C. 4

Iterate the recurrence with reduction mod 11 at each step, so the values stay small. Reducing only at the end gives the same answer but risks overflow in fixed-width languages.

More Coding Interview Problems questions

Exams that ask this topic