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?

  1. A. 10
  2. B. 8
  3. C. 18
  4. 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

Exams that ask this topic