JAVA | DP Easy Solution With Explanation | Well Commented
\nclass Solution {\n    public int minDistance(String str1, String str2) {\n        int m = str1.length();\n        int n = str2.length();\n        int dp[][] =
```\nclass Solution {\n    public int minDistance(String str1, String str2) {\n        int m = str1.length();\n        int n = str2.length();\n        int dp[][] = new int[m + 1][n + 1]; \n        // Fill d[][] in bottom up manner \n        for (int i = 0; i <= m; i++) { \n            for (int j = 0; j <= n; j++) { \n                // If first string is empty, only option is to \n                // insert all characters of second string \n                \n                if (i == 0) dp[i][j] = j; // Min. operations = j \n                \n                // If second string is empty, only option is to \n                // remove all characters of second string \n                \n                else if (j == 0) \n                    dp[i][j] = i; // Min. operations = i \n                \n                // If last characters are same, ignore last char \n                // and recur for remaining string \n                \n                else if (str1.charAt(i - 1) == str2.charAt(j - 1)) \n                    dp[i][j] = dp[i - 1][j - 1]; \n  \n                // If the last character is different, consider all \n                // possibilities and find the minimum \n                else\n                    dp[i][j] = 1 + Math.min(Math.min(dp[i][j - 1], // Insert \n                                       dp[i - 1][j]), // Remove \n                                       dp[i - 1][j - 1]); // Replace \n            } \n        } \n  \n        return dp[m][n]; \n    }\n}\n```
['Dynamic Programming', 'Java']