Count ways to increase LCS length of two strings by one
Submissions: 413   Accuracy:

23.47%

  Difficulty: Medium   Marks: 4

Given two strings of lower alphabet characters, we need to find the number of ways to insert a character in the first string such that length of LCS of both strings increases by one.

 

Input:

The first line of the contains T denoting the number of testcases. Then T testcases follow. The first line of each test case contains integers N and M denoting the length of strings str1 and str2.

The second line of each test case contains the strings str1 and str2 consisiting of only lower case alphabets.


Output:

Print the answer for each test case in a new line.


Constraints:

1<= T <=100

1<= N, M <=100


Example:

Input:

1

5 3

abab abc

Output:

3

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sujnesh Mishra
Author: sujnesh


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.