Getting TLE for all test cases except case3

Question: https://online.codingblocks.com/app/player/178555/content/173738/5208/code-challenge

Solution: https://ide.codingblocks.com/s/452883

Getting TLE for test-cases: 0, 1, 2, 4
Cetting correct answer while compilation and for test-case 3.

I have no idea how should I optimize this.

hello @mohaktrivedi

use dynamic programming.
ur recusive solution has exponential time complexity thats why it is giving tle

@aman212yadav
Oh! Actually this is a problem from ‘Challenges - Recursion’ section in the course so I thought we have to use Recursive solution. I haven’t learned Dynamic Programming yet. It’s a bit ahead in the course.

…

no issue, u can try this after learning dp.

btw ur recusive solution is correct

@aman212yadav
Alright! Thanks, happy to know it’s correct!

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.