Test case 1 wrong.where wrong in my code

#include
#include
#include
using namespace std;
int main(){
string pre,post;
cin>>pre>>post;
int n=pre.length();
int m=post.length();
int dp[m+1][n+1];
for(int i=0;i<=m;i++){
dp[i][0]=0;
}
for(int i=0;i<=n;i++){
dp[0][i]=0;
}
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
if(pre[i-1]==post[j-1]){

        dp[i][j]=dp[i-1][j-1]+1;
    }
    else{
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
}

}

int index = dp[m][n];

// Create a character array to store the lcs string
char lcs[index+1];
lcs[index] = ‘\0’; // Set the terminating character

int i = m, j = n;
while (i > 0 && j > 0)
{

  if (pre[i-1] == post[j-1]) 
  { 
      lcs[index-1] = pre[i-1]; 
      i--; j--; index--;     
  } 

 
  else if (dp[i-1][j] > dp[i][j-1]) 
     i--; 
  else
     j--; 

}
cout << lcs;
}

@dineshjani Please provide code in coding blocks IDE.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.