Wrong answer for the problem tiling problem 2

I tried to solve the problem tilting problem 2 and I used a dp approach, but it is only showing correct output for the given sample test case but showing wrong output for all the other test cases. The code is given at β€”> https://ide.codingblocks.com/s/266884

hi @souptiksarkar4572 there were a few logical errors, here’s the corrected code


Dont forget to mark your doubt as resolved :slight_smile:

Okay I got it. So we have to handle the negative or zero numbers and positive numbers differently.

One more thing, I don’t know if I am giving any wrong input but the output is getting some garbage values.

hi @souptiksarkar4572 i think one more base case is needed for n==m
and the size of array should be n+1 (because we want nth index as well), in the earlier code, nth index contained garbage value and so the function returns from the base case only and printed that garbage value
this code is giving correct output https://ide.codingblocks.com/s/266890

Thank you very much for pointing it out. One more thing, the base case n==m, can it be covered in subsequent recursive calls if we consider that n==0 would return 1.

@souptiksarkar4572 yeah that would also work, they are both logically correct. Please mark your doubt as resolved if you dont have any further queries :slight_smile:

Thank you very much. All my doubts have been solved.

1 Like