Data Structures & AlgorithmsVery hardGATE CS

A walker moves from (0,0) to (4,4) on lattice points using steps (1,0), (0,1) and (1,1). The point (2,2) is forbidden. How many different paths exist?

  1. A. 222
  2. B. 152
  3. C. 285
  4. D. 321

Correct answer: B. 152

Count with the recurrence f(x,y)=f(x+1,y)+f(x,y+1)+f(x+1,y+1) and f(2,2)=0, giving 152. Without the restriction there are 321 paths (Delannoy number D(4,4)); paths through (2,2) number D(2,2)² = 13² = 169, and subtracting only 6² = 36 (the diagonal-free count) leaves the wrong 285.

More Coding Interview Problems questions

Exams that ask this topic