Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: A robot is on a 4×4 torus (moving off one edge reappears on the opposite edge) starting at (0,0), using row, column coordinates. It executes the moves R, R, D, D, L, U, R, D, D, R, with R = column+1, L = column−1, D = row+1, U = row−1, all mod 4. What is its final row × 10 + final column?

  1. A. 13
  2. B. 31
  3. C. 44
  4. D. 33

Correct answer: D. 33

Tracking (row, col) mod 4: R, R → (0,2), D, D → (2,2), L → (2,1), U → (1,1), R → (1,2), D, D → (3,2), R → (3,3), so 33. Swapping the meanings of D and U gives 13, swapping L and R gives 31, and reporting 1-indexed coordinates gives 44.

More Coding Interview Problems questions

Exams that ask this topic