Correct output yet WA

i have seen the hint video and already submitted the correct answer but why isn’t this answer submitting when even the output is coming correct?

#include<bits/stdc++.h>
#include<cstring.h>
using namespace std;
void lcs(string s1,string s2)
{
int n=s1.length();
int m=s2.length();
int dp[n+1][m+1];
for(int i=0;i<=n;i++) dp[i][0]=0;
for(int j=0;j<=m;j++) dp[0][j]=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(s1[i-1]==s2[j-1])
{
dp[i][j]=1+dp[i-1][j-1];
}
else
{
dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
}
}
}
int index= dp[n][m];
char lcs[index+1];
lcs[index]=’\0’;
int i=n,j=m;
int temp=index;
while(i>0 && j>0 && index>0)
{
if(dp[i][j-1] == dp[i-1][j] && dp[i][j] > dp[i][j-1])
{
lcs[index-1]=s1[i-1];
i–;
j–;
index–;
}
else if(dp[i][j-1] == dp[i][j])
{
j–; // we move one step back
}
else
{
i–;

    }
}
for(int i=0;i<temp;i++)
{
	cout<<lcs[i];
}

}
int main() {
string s1,s2;
cin>>s1>>s2;
lcs(s1,s2);
return 0;
}

i know what is the correct way to code this, as this way is also told in the hint video. I want to know why the way which i have applied is not working

answer not submitting or getting WA?

Yes and when i compare the characters to form the dp array and at the same time add them to a new string.

Your new code is missing some statements which are present in the older one which you have not implemented