Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The matrix [[1,2,3],[4,5,6],[7,8,9]] is traversed by rows, but with each row read alternately left-to-right and right-to-left (boustrophedon). What is the value at index 4 (0-indexed) of this sequence?

  1. A. 5
  2. B. 6
  3. C. 4
  4. D. 7

Correct answer: A. 5

The odd-numbered rows are read in reverse, so the sequence is 1 2 3 6 5 4 7 8 9 and index 4 holds 5. Reading every row left to right gives a different value.

More Coding Interview Problems questions

Exams that ask this topic