Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A 3×4 grid has walls '#' at (0,2), (1,1), (2,3). Moves go up, down, left and right through open cells. Starting from (0,0), how many open cells are at shortest-path distance exactly 4?

  1. A. 1
  2. B. 2
  3. C. 0
  4. D. 3

Correct answer: A. 1

BFS assigns each reachable open cell its shortest distance, and the question counts those at exactly four steps. Cells that are reachable but farther away, or walls, are excluded.

More Coding Interview Problems questions

Exams that ask this topic