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?
- A. 13
- B. 31
- C. 44
- 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
- Problem: Evaluate the postfix expression "3 4 + 2 7 −" using a stack (the operator pops the top two values, computes second-from-top op…
- Problem: Rule 30 cellular automaton on an infinite line starts with a single live cell. Each generation, a cell's new state is determined…
- Problem: How many integers x with 1 ≤ x ≤ 100 have an odd number of set bits in their binary representation AND are odd themselves?
- Problem: What is the minimum number of bit flips needed to convert 29 into 15 (flips of single bits in binary)?
- Problem: What is the largest power of 2 that divides 480 × 36?
- Problem: How many pairs (a, b) with 1 ≤ a < b ≤ 20 satisfy gcd(a, b) = 1?