#K6181. Smallest Supersequence Length
Smallest Supersequence Length
Smallest Supersequence Length
Given two strings A
and B
, your task is to determine the length of the smallest string that contains both A
and B
as subsequences. This length can be computed using the formula:
$$|A| + |B| - \text{LCS}(A,B)$$
where \text{LCS}(A,B)
is the length of the longest common subsequence between A
and B
.
You are required to process multiple test cases. For each test case, output the answer on a separate line.
inputFormat
The first line of the input contains an integer T
denoting the number of test cases. Each of the following T
lines contains two space-separated strings A
and B
.
Example:
2 abc ac horizon noz
outputFormat
For each test case, print a single line containing the length of the smallest supersequence which has both A
and B
as subsequences.
Example:
3 8## sample
2
abc ac
horizon noz
3
8
</p>