Timer is Running

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


  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.



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.


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


1<= T <=100

1<= N, M <=100




5 3

abab abc



** 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.