Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: A sequence is defined by a1 = 1, a2 = 1, and an = an−1 + an−2 mod 7 for n ≥ 3. What is a30 (1-indexed)?
- A. 6
- B. 2
- C. 1
- D. 832040
Correct answer: A. 6
Fibonacci numbers mod 7 repeat with Pisano period 16, so a30 = a14 = 377 mod 7 = 6. Shifting the index by one gives a29 = 2 or a31 = 1, and forgetting the reduction leaves F30 = 832040.
More Coding Interview Problems questions
- Problem: A grid of size 3×4 has the cell values 1 to 12 filled row-wise. Starting at the top-left (value 1), you may move right or down…
- For a = [2, -1, 4, -3, 5], which of the following statements is TRUE? A. Some contiguous subarray sums to 7. B. Every prefix sum from the…
- What does this program print? python a = [1, -1, 2, -2, 3] seen = {0: 0} s = 0; out = [] for i, x in enumerate(a, 1): s += x if s in seen…
- What does this program print? python best = None s = 0 for x in [4, -2, -2, 3, -1]: s += x best = s if best is None else max(best, s)…
- Array [1, 3, 2, 6, 4, 5, 7, 8]. How many inversions does it have (index pairs i < j with a[i] > a[j])?
- Sequence [5, 2, 9, 1, 7, 3]. Consider only index pairs i < j with j - i <= 2. What is the largest value of |a[i] - a[j]| over these pairs?