I think there is some mistake in output say n=5 and k=3
then for a[4]=7 ways, a[3]=4 ways, a[2] = 2 ways and a[1]=1 ways total is 14 but according to provided code ans is 13 please if someone can call and clear my doubt regarding this as I can’t discuss over chat
Ans in Ladders DP
Hey so we stand at 0th position
Now A[i] represents no of ways to reach i
so we can reach 1 by taking jump of 1 so 1 way
we can reach 2 by taking jump of 2 or 1+1 so 2 ways
we can reach 3 by taking jump of 3 or 1+1+1 or 1+2 or 2+1 so 4 ways
And we can reach 4 from 3rd 2nd and 1st so we add their no of ways = 4+2+1 =7
Now we can reach 5 from 4th ,3rd,2nd so we add their ways = 7+4+2 =13
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.