GATE Computer ScienceHardGATE CS (PYQ pattern)

A 4 x 6 matrix (4 rows, 6 columns) holds 1 to 24 in row-major order. Its elements are visited in an anticlockwise spiral that starts at the top-left corner and first goes down the first column. What is the sum of the 10th, 15th and 20th visited elements?

  1. A. 47
  2. B. 37
  3. C. 43
  4. D. 31

Correct answer: B. 37

The anticlockwise spiral is 1 7 13 19 20 21 22 23 24 18 12 6 5 4 3 2 8 14 15 16 17 11 10 9. The 10th, 15th and 20th elements are 18, 3 and 16, summing to 37. The usual clockwise spiral gives 47.

More Programming and Data Structures (GATE) questions

Exams that ask this topic