Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2

5 × 5 grid, rows top to bottom ('#' = wall, '.' = open): ..... / ###.. / ....# / ...## / ##.#.. Start at top-left, target bottom-right. Each move goes to one of the 4 neighbouring cells, and every time you step INTO a '#' cell it counts against a budget of 1 such entries in total. What is the minimum number of moves?

  1. A. 8
  2. B. 10
  3. C. no path
  4. D. 9

Correct answer: B. 10

A BFS over states (cell, wall-entries used) gives 10 moves; with no wall budget the route is no path. The Manhattan distance 8 is only a lower bound and ignores the walls.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic