🎙 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 13 of 13

Before reading a neighbour (nr, nc), what must you check?

Before reading a neighbour (nr, nc), what must you check?

  1. A.That nr equals nc
  2. B.That the neighbour's value is positive
  3. C.That the grid is square
  4. D.That 0 <= nr < rows and 0 <= nc < cols
Answer & explanation

Correct answer: That 0 <= nr < rows and 0 <= nc < cols

Without the bounds check, an edge cell's neighbour is outside the grid. In Python a negative index would even read the wrong cell silently.

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 →