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)?
- A. 5
- B. 3
- C. 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
- Problem: A bag holds coins of values 1, 4 and 9. You must pay exactly 30 using as few coins as possible. What is the minimum number of…
- Problem: The 0/1 matrix [[1,0,1],[1,1,0],[0,1,1]] is considered. A 'plus' is a centre cell with value 1 whose four neighbours (up, down…
- Problem: Two heaps are maintained over the stream 5, 15, 1, 3, 8, 7, 9, 10, 6, 11 to report the median after each element (lower median…
- Problem: The string "abcabcbb" is scanned and for each position the length of the longest run of distinct characters starting at that…
- Problem: Dijkstra's algorithm in an undirected graph with edges 0-1 (2), 1-2 (2), 0-2 (5), 2-3 (1), 1-3 (6). How many vertices have a…
- Problem: The string "xyyxzzyx" is examined for palindromic substrings of length 4 or more. How many such palindromic substrings are there…