//
// main.cpp
// Edit Distance
//
// Created by Himanshu on 16/09/21.
//
#include <iostream>
#include <string>
using namespace std;
int solve (string s1, string s2) {
int n = (int) s1.length(), m = (int) s2.length();
int dp[n+1][m+1];
for (int i=0; i<=n; i++) {
for (int j=0; j<=m; j++) {
dp[i][j] = 0;
}
}
for (int i=0; i<=n; i++) {
dp[i][0] = i;
}
for (int j=0; j<=m; j++) {
dp[0][j] = j;
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
if (s1[i-1] == s2[j-1]) {
dp[i][j] = dp[i-1][j-1];
}
else {
dp[i][j] = 1 + min((min(dp[i-1][j],
dp[i][j-1])),
dp[i-1][j-1]);
}
}
}
return dp[n][m];
}
int main() {
string s1 = "hello", s2 = "tell";
cout<<solve(s1, s2)<<endl;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBFZGl0IERpc3RhbmNlCi8vCi8vICBDcmVhdGVkIGJ5IEhpbWFuc2h1IG9uIDE2LzA5LzIxLgovLwoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IHNvbHZlIChzdHJpbmcgczEsIHN0cmluZyBzMikgewogICAgaW50IG4gPSAoaW50KSBzMS5sZW5ndGgoKSwgbSA9IChpbnQpIHMyLmxlbmd0aCgpOwogICAgaW50IGRwW24rMV1bbSsxXTsKICAgIAogICAgZm9yIChpbnQgaT0wOyBpPD1uOyBpKyspIHsKICAgICAgICBmb3IgKGludCBqPTA7IGo8PW07IGorKykgewogICAgICAgICAgICBkcFtpXVtqXSA9IDA7CiAgICAgICAgfQogICAgfQogICAgCiAgICBmb3IgKGludCBpPTA7IGk8PW47IGkrKykgewogICAgICAgIGRwW2ldWzBdID0gaTsKICAgIH0KICAgIAogICAgZm9yIChpbnQgaj0wOyBqPD1tOyBqKyspIHsKICAgICAgICBkcFswXVtqXSA9IGo7CiAgICB9CiAgICAKICAgIGZvciAoaW50IGk9MTsgaTw9bjsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaj0xOyBqPD1tOyBqKyspIHsKICAgICAgICAgICAgaWYgKHMxW2ktMV0gPT0gczJbai0xXSkgewogICAgICAgICAgICAgICAgZHBbaV1bal0gPSBkcFtpLTFdW2otMV07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICBkcFtpXVtqXSA9IDEgKyBtaW4oKG1pbihkcFtpLTFdW2pdLCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkcFtpXVtqLTFdKSksIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRwW2ktMV1bai0xXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgCiAgICAgICAgfQogICAgfQogICAgCiAgICByZXR1cm4gZHBbbl1bbV07Cn0KCmludCBtYWluKCkgewogICAgc3RyaW5nIHMxID0gImhlbGxvIiwgczIgPSAidGVsbCI7CiAgICBjb3V0PDxzb2x2ZShzMSwgczIpPDxlbmRsOwp9Cg==