Sherlock and cost... Hackerrank DP problem

dynamic-programming
easy
hackerrank
tle

#1

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

Here is the solution with test cases (downloaded) ideone


#2

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) .


#3

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