Can this be done without dp?

i tried using normal recursion and it runs on various custom inputs to, but it fails when i submit. Dp is used in the solution so is it the only way?

hello @ashutosh_singh
recursive solution is also correct it fails(gives tle) because of high time complexity .

dp/memoisation will help u in reducing the time complexity so use it in ur recursive approach.

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.