← Quiz: Matrix Traversal: all 13 questions
Quiz: Matrix Traversal · Question 12 of 13
In grid problems, what are direction arrays such as dr = [-1, 1, 0, 0] and dc = [0, 0, -1, 1] for?
In grid problems, what are direction arrays such as dr = [-1, 1, 0, 0] and dc = [0, 0, -1, 1] for?
- A.They list the row and column changes to reach the up, down, left and right neighbours in one loop
- B.They store the four corners of the grid
- C.They sort the grid in four directions
- D.They rotate the grid by 90°
Answer & explanation
Correct answer: They list the row and column changes to reach the up, down, left and right neighbours in one loop
One loop over dr and dc replaces four nearly identical if-blocks.
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 →