Data Structures & AlgorithmsHardGATE CS · competitive programming

A 4×5 matrix holds the value r·5 + c + 1 at row r and column c (0-based). Visited in spiral order from the top-left corner, what is the 10th value?

  1. A. 17
  2. B. 10
  3. C. 15
  4. D. 18

Correct answer: D. 18

The spiral runs 1, 2, 3, 4, 5, 10, 15, 20, 19, 18, so the 10th value is 18. Row-major order would give 10 instead.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic