Data Structures & AlgorithmsHardTCS NQT · Accenture

Problem: A matrix of size 4×4 is filled row-wise with 1 to 16 (row 0 holds 1–4, row 1 holds 5–8, and so on). It is rotated 90 degrees clockwise. After rotation, what value is at row 1, column 2 (0-indexed)?

  1. A. 6
  2. B. 11
  3. C. 10
  4. D. 7

Correct answer: A. 6

A clockwise rotation maps new[i][j] = old[n − 1 − j][i], so new[1][2] = old[1][1] = 6. Rotating counter-clockwise gives old[2][2] = 11, transposing without reversing gives old[2][1] = 10, and reading the unrotated matrix gives 7.

More Coding Interview Problems questions

Exams that ask this topic