Hii…
I am doing this question from hackerearth…
I have used recursion+memoization… to solve this problem…
I have used map for memoization…
This is my submission…
https://www.hackerearth.com/submission/51684573/
It is showing tle in 3 out of 20 test cases…
Please see this…
Can some improvement be done in this code… so that this question could be solved by recursion+memoization…
Thanks