Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS

Grid with 3 rows and 3 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .GG G.. ... Each step, which is a move to an adjacent cell or waiting one unit in place, takes exactly 1 time unit. A gate may only be occupied at an even time (t = 0, 2, 4, …); normal cells can be occupied at any time. You start at the top-left cell at time 0. What is the earliest time you can stand on the bottom-right cell?

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

Correct answer: C. 5

A BFS over (cell, time) states gives 5, since waiting is allowed and gates block odd arrival times. Ignoring gates gives 4, and forbidding waiting gives no answer.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic