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?
- A. 4
- B. 3
- C. 2
- 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
- Problem: How many subsets of {1, 2, 3, 4, 5, 6} contain exactly two odd numbers?
- Problem: The product of the first 6 positive odd numbers 1·3·5·7·9·11 is computed. What is that product's value modulo 100?
- Problem: A cyclic array [1, 2, 3, 4, 5] is rotated so that the element at index 0 becomes the element at index 2 (rotate left by 2). What…
- Problem: Starting from 5 on a number line, you may jump +2 or +3 each turn and must land exactly on 25. How many distinct jump sequences…
- Problem: A rectangle of 12 by 18 units is cut into the largest possible identical squares that tile it exactly. How many such squares are…
- Problem: The number 720 is written as a product of primes. What is the sum of its distinct prime factors?