Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

A grid has 8 rows and 6 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): ...#.. ..##.# ...#.. #..#.. ..###. .#.#.. ....## .##... Starting at the top-left cell, what is the minimum number of moves to reach the bottom-right cell, where a move goes to one of the four side-adjacent open cells?

  1. A. 12
  2. B. 14
  3. C. 15
  4. D. 8

Correct answer: B. 14

A BFS over open cells gives 14 moves, the detour forced by the walls. The Manhattan distance 12 ignores walls, and allowing diagonal moves gives 8.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic