Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS

A grid has 6 rows and 4 columns (top to bottom; '.' open, '#' blocked): .... #... .... #... ..#. ..#. You may only move right or down, and you cannot enter a blocked cell. How many different routes lead from the top-left cell to the bottom-right cell?

  1. A. 52
  2. B. 56
  3. C. 20
  4. D. 10

Correct answer: D. 10

Let ways[cell] = ways from above + ways from the left, with 0 for blocked cells. The total is 10. Ignoring the blocks would give 56, and subtracting one per blocked cell (a common shortcut) gives 52.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic