C++ easy solution using dp

google
programming
amazon
interview-questions
Tags: #<Tag:0x00007f24284b81a8> #<Tag:0x00007f24284b8068> #<Tag:0x00007f24284c3ee0> #<Tag:0x00007f24284c3d00>

#1

int Solution::minDistance(string A, string B) {
int m=A.size();
int n=B.size();
vector<vector> dp(m+1,vector(n+1,0));
reverse(A.begin(),A.end());
int a=m;
int b=0;
for(int i=0;i<=m;i++)
{
dp[i][0]=a;
a–;
}
for(int j=0;j<=n;j++)
{
dp[m][j]=b;
b++;
}
for(int i=m-1;i>=0;i–)
{
for(int j=1;j<=n;j++)
{
if(A[i]==B[j-1])
{
dp[i][j]=dp[i+1][j-1];
}
else
{
int x =min(dp[i][j-1],dp[i+1][j-1]);
int y= min(x,dp[i+1][j]);
dp[i][j]=y+1;
}
}
}
return dp[0][n];
}


#2

BETA , why are u reversing the string…ratt k aye ho??


#3

@nishant-joshi_133 if you don’t know the solution just go through the comment section and learn don’t try to criticize others.


#4

mind your business. Dont over react this was not political
comment


#5

I never said it was political. I meant that if you can’t be thankful to people just don’t demotivate them.