Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: The sequence a0 = 0 and a(n) = a(n−1) + (n mod 3) for n ≥ 1 is defined. What is a(30)?
- A. 30
- B. 465
- C. 60
- D. 0
Correct answer: A. 30
Each block n ≡ 1, 2, 0 adds 1 + 2 + 0 = 3, and 1..30 is 10 blocks, so a(30) = 30. Forgetting the mod gives 465, using 1 + 2 + 3 per block gives 60, and 0 is just 30 mod 3.
More Coding Interview Problems questions
- Problem: A square matrix 4×4 has entry (i, j) equal to (i + 2j) mod 5. What is the sum of the entries on the main diagonal?
- Problem: The sum of the squares of the first 15 natural numbers, reduced modulo 7, is what value?
- Problem: Consider the array [3, 7, 4, 9, 2, 8, 5]. Two selection rounds are performed: first pick the largest value and remove it, then…
- Problem: Dictionary: a list of words is ["cat", "dog", "bat", "dig"]. Words are grouped by changing exactly one letter (Hamming distance…
- Problem: Starting at (0,0), a robot moves on an infinite grid using the string "UURDDLLUR" (U = up, D = down, L = left, R = right). The…
- Problem: The set S = {1, 2, 3, …, 30} is considered. How many integers in S are NOT divisible by 2, 3 or 5?