Minimum number of deletions and insertions.

Given two strings ‘str1’ and ‘str2’ of size m and n respectively. The task is to remove/delete and insert minimum number of characters from/in str1 so as to transform it into str2. It could be possible that the same character needs to be removed/deleted from one point of str1 and inserted to some another point.


The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains integers N and M denoting the length of the strings str1 and str2. Both the strings consist of only small letter alphabets.

The second line of each test case contains the strings str1 and str2.

Print the total no of insertions and deletions to be done to convert str1 to str2. Output the answer in a new line.

1<= T <=100

1<= N, M <=1000



4 3

heap pea



**For More Examples Use Expected Output**


Disclaimer: This content belongs to geeksforgeeks, source:


Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar