Generation

generate functionMon, 02 Jan 2023

# The deletion distance between two strings is the minimum sum of ASCII values of characters that you need to delete in the two strings in order to have the same string The deletion distance between "cat" and "at" is 99, because you can just delete the first character of cat and the ASCII value of 'c' is 99. The deletion distance between "cat" and "bat" is 98+ 99, because you need to delete the first character of both words. Of course, the deletion distance between two strings can't be greater than the sum of their total ASCII values, because you can always just delete both of the strings entirely. Implement an efficient function to find the deletion distance between two strings. You can refer to the Wikipedia article on the algorithm for edit distance if you want to. The algorithm there is not quite the same as the algorithm required here,

``````public static int makeAnagram(String a, String b) {
// Complete this function
if(a.length() == 0 || b.length() == 0) return a.length() + b.length();
int[][] matrix = new int[a.length() + 1][b.length() + 1];
for(int i = 0; i <= a.length(); i++){
matrix[i] = i;
}
for(int i = 0; i <= b.length(); i++){
matrix[i] = i;
}

for(int i = 1; i <= a.length(); i++){
for(int j = 1; j <= b.length(); j++){
int cost = 0;
if(a.charAt(i - 1) == b.charAt(j - 1)){
cost = 0;
}else{
cost = 1;
}
matrix[i][j] = Math.min(Math.min(matrix[i - 1][j``````