Data Structures & AlgorithmsHardCodeforces Div2 C

Grid rows (top to bottom): '....', '.#..', '...#', '#...', '....'. '#' is an obstacle, '.' is free. Starting at the top-left cell, you move only right or down, and you may not enter obstacles. How many paths reach the bottom-right cell?

  1. A. 35
  2. B. 0
  3. C. 14
  4. D. 7

Correct answer: D. 7

The count is dp[r][c] = dp[r-1][c] + dp[r][c-1] for free cells, and dp = 0 on obstacles. Ignoring the obstacles or forgetting the 'right only' restriction changes the number, and doubling is the usual mistake of counting mirror routes.

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

Exams that ask this topic