Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: A sequence is defined by s(1) = 1, s(2) = 2, and s(n) = s(n−1) + s(n−2) for n ≥ 3. What is the remainder when s(12) is divided by 10?

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

Correct answer: B. 3

Compute the sequence (a Fibonacci-like sequence starting 1, 2) up to term 12 and take the last digit. The last digit of a sum depends only on the last digits of its parts, so reducing mod 10 at each step works too.

More Coding Interview Problems questions

Exams that ask this topic