(UPDATED)Can someone please explain how to make it memory efficient?
update: found my mistake , i missed an &  with the string due to which it was copied again and again with every recursion \uD83E\uDD72. \n\nclass Solution {\npu
update: found my mistake , i missed an &  with the string due to which it was copied again and again with every recursion \uD83E\uDD72. \n```\nclass Solution {\npublic:\n    int dp(int i,string pk,vector<int> &lim,vector<int> &v)\n    {if(i==pk.size()){return 1;}\n     if(v[i]!=-1){return v[i];}\n        int ways=0,cnt=0;\n        for(int j=i;j<pk.size();j++)\n        {cnt++;\n            \n            ways=(ways+dp(j+1,pk,lim,v))%1000000007;\n            if(pk[j]!=pk[j+1]||cnt>=lim[pk[j]-\'0\']){break;}\n        }\n     return v[i]=ways;\n    }\n    int countTexts(string pressedKeys) {\n        vector<int> lim(10,3);lim[7]++;lim[9]++;\n        vector<int> v(pressedKeys.size(),-1);\n        return dp(0,pressedKeys,lim,v);\n    }\n};\n```
['Dynamic Programming', 'Recursion']