Data Structures & AlgorithmsModerateTCS NQT · Accenture
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?
- A. 10
- B. 8
- C. 18
- D. 32
Correct answer: B. 8
Diagonal entries are 3i mod 5 for i = 0..3: 0, 3, 1, 4, sum 8. Using i = 1..4 gives 3 + 1 + 4 + 2 = 10, skipping the mod gives 18, and 32 sums the whole matrix.
More Coding Interview Problems questions
- 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?
- Problem: A binary search over the sorted array [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] looks for the value 12 which is absent. Using the…