Solution Partially correct showing TLE for higher values


int static t[1007][1007];
int lcs(string A, string B, int n, int m)
if(n==0 || m==0) return 0;
if(t[n][m]!=-1) return t[n][m];
return t[n][m]= 1+lcs(A,B,n-1,m-1);
return t[n][m]= max(lcs(A,B,n-1,m), lcs(A,B,n,m-1));
int Solution::solve(string A, string B) {
int n=A.size();
int m=B.size();
int count=lcs(A,B,n,m);
return count;


Bro, you either have to use memoization or dynamic programming to solve this problem efficiently.