Only passing test case 3

Here is my code:


It was giving TLE using recursion so i tried using dp. It still passes only test case 3. Please check

hello @Garvit012
image
it should be i in place of n.

its working now…thanks a ton for your help