I am doing this problem on Spoj and I have written the recursive solution. Which according to me is right. This solution is giving me TLE, so I change to memoization solution. This memoization solution is giving me WA.
Is my memoization of recursive solution wrong? If yes then why and if no then why is it not giving AC.
Is there any better way to do memoization?