Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS

A grid has 7 rows and 8 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. 13
  2. B. 15
  3. C. 7
  4. D. 16

Correct answer: B. 15

A BFS over open cells gives 15 moves, the detour forced by the walls. The Manhattan distance 13 ignores walls, and allowing diagonal moves gives 7.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic