Sherlock and cost... Hackerrank DP problem

Why does this code time out?? Link to the problem problem

Here is the solution with test cases (downloaded) ideone

You are using recurse . instead first you need to check if this computation is already done or not . if not then recurse and save the result in some memo. otherwise use the stored value (what the point of using DP if you are doing same computation again and again) .

I have memoized it already ! :slight_smile: Please see it again carefully…