🎙 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 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?

  1. A.They list the row and column changes to reach the up, down, left and right neighbours in one loop
  2. B.They store the four corners of the grid
  3. C.They sort the grid in four directions
  4. 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 →