🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Matrix Traversal: all 13 questions

Quiz: Matrix Traversal · Question 8 of 13

In the spiral code, what goes wrong without the if top <= bottom check on a 1 × 3 matrix [[1, 2, 3]]?

In the spiral code, what goes wrong without the if top <= bottom check on a 1 × 3 matrix [[1, 2, 3]]?

  1. A.Nothing changes
  2. B.The single row is printed again backwards: 1 2 3 2 1
  3. C.It prints an empty list
  4. D.It loops forever
Answer & explanation

Correct answer: The single row is printed again backwards: 1 2 3 2 1

After the top row is printed, top > bottom; without the check the "bottom row, right to left" step prints it again.

Can you get the rest right without peeking?

Take the timed Quiz: Matrix Traversal quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →