Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A 2×4 grid has a wall at (0,2) (row, column, 0-indexed); all other cells are open. Moves go up, down, left or right. What is the shortest distance from (0,0) to (1,3)?

  1. A. 4
  2. B. 5
  3. C. 3
  4. D. 6

Correct answer: A. 4

The wall at (0,2) forces the route through row 1: (0,0)→(1,0)→(1,1)→(1,2)→(1,3), which takes four moves. The Manhattan distance of 4 is achievable here because the detour is along the bottom row.

More Coding Interview Problems questions

Exams that ask this topic