Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

A 2 × 5 grid has obstacles at (row, column) positions [(0, 2), (1, 3)] (rows 0 and 1, columns 0 to 4). Starting at (0,0), you move one step right or down, never entering an obstacle, and you must reach (1, 4). How many paths exist?

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

Correct answer: C. 0

dp over cells: each free cell's count is the sum of the cell above and the cell to the left, and an obstacle's count is zero. Ignoring the obstacles gives the unrestricted count, which is larger.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic