← 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?
- A.That nr equals nc
- B.That the neighbour's value is positive
- C.That the grid is square
- 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 →