Google interview question on DP

There are N stairs counting from 1...N with N being the highest stair. A ball is kept at stair N. Find no. of ways in which ball can reach ground. Conditions:

  1. Ball can only make jump by 1,2,3 steps in odd attempts and by 1,3,4 steps in even attempt.
  2. There are one or more sticky stairs where if the ball lands then it can not move down further.

Ball can overshoot and reach ground. Means if the ball is at last stair 1 and at odd attempt then it can reach ground in 3 ways(1,2,3 steps). Similar for even attempt also.

Eg.
N = 3
Sticky stair = 2

---+
3|
|
+----+
2|
|
+----+
1|
|
+-------------------
No. of ways = 4
3->G
3->1->G (1 step from 1)
3->1->G (3 step from 1)
3->1->G (4 step from 1)

Comments (4)