Data Structures & AlgorithmsHardTCS NQT · Infosys

A robot moves only right or down from the top-left to the bottom-right cell of this 6×6 grid, where # is a blocked cell and . is free: ...... ..#... .#..#. ....#. #..... ...... How many distinct paths exist?

  1. A. 20
  2. B. 24
  3. C. 18
  4. D. 15

Correct answer: C. 18

Run dp[i][j] = dp[i-1][j] + dp[i][j-1] with dp = 0 on blocked cells and dp[0][0] = 1. The bottom-right entry evaluates to 18.

More Coding Interview Problems questions

Exams that ask this topic