Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Starting at the number 2, repeatedly apply f(x) = x² + 1 modulo 11. What is the value after 5 applications?
- A. 4
- B. 5
- C. 1
- D. 6
Correct answer: D. 6
2 → 5 → 26 ≡ 4 → 17 ≡ 6 → 37 ≡ 4 → 17 ≡ 6, so after five steps the value is 6 (it alternates 4, 6). Stopping after four gives 4, one step gives 5, and reducing mod 10 gives 1.
More Coding Interview Problems questions
- Problem: The array [2, 3, 4, 5, 6, 7, 8] is examined for the number of subsets whose sum is a perfect square (the empty subset has sum 0…
- Problem: In the string "xyxyxy", how many substrings of length 4 are palindromes?
- Problem: A sequence of 10 operations applies to an initial value of 0: operation i (1 ≤ i ≤ 10) adds i if i is odd and multiplies the…
- Problem: A graph's adjacency list is 0: [1, 2], 1: [3], 2: [3, 4], 3: [5], 4: [5], 5: []. What is the number of distinct topological…
- Problem: The number of integers from 1 to 100 that have exactly three divisors is what value? (Numbers with exactly three divisors are…
- Problem: What is the number of inversions in the array [4, 3, 2, 1, 0]?