Tilling Problem------------------------

Here is the code that i wrote , i have used recursion with memoization to solve this problem but im getting only one test case correct.
I’m not getting what mistake i am making.
Please point out my mistake

@neil_gautam you are not using the memo array correctly.

  1. Its size should be n+1 so you can access memo[n]
  2. In the recursive case before you make a recursive call, check if answer exists in memo array or not, if it does then you dont need to make the recursive call.
if (memo[n] != 0) {
     return memo[n];
 }

@neil_gautam
also

 return  memo[n-1]+memo[n-m];

is not correct,

you should take modulo each time with 10^9 +7 (as given in the question) and update your memo[n] if you have to calculate it using recursion…
See below;

Correction required :
return memo[n]=(memo[n-1]+memo[n-m])%mod;
where mod=10^9 +7

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.