Longest Common Subsequence of Three Strings
Given three strings A, B, and C, the task is to determine the length of the longest common subsequence across these three strings.
Explanation:
A subsequence of a string is a sequence that can be derived by deleting some characters (possibly zero) from the original string without changing the order of the remaining characters. For instance, "cde" is a subsequence of "code", but "cdo" is not. A common subsequence among multiple strings is one that appears in each of those strings.
Input:
The first line contains an integer 'T', representing the number of test cases. For each test case:
The first line contains three space-separated positive integers n, m, k, representing the lengths of strings A, B, and C respectively.
The second line contains the string A.
The third line contains the string B.
The fourth line contains the string C.
Output:
For each test case, return the length of the longest common subsequence among the three strings A, B, and C.
Example:
Input:
2
3 3 3
abc
abc
abc
4 4 4
abcd
aefg
bcdf
Output:
3
1
Explanation:
In the first test case, 'abc' is the common subsequence among all three strings, thus the length is 3. In the second test case, the common subsequence is 'c', so the length is 1.
Constraints:
- 1 <= T <= 5
- 1 <= n, m, k <= 100
- n, m, k denote the lengths of strings A, B, and C, respectively.
- Time limit: 1 second
Note:
You don’t need to print anything. Just complete the function. If there is no common subsequence, return 0.
Top DE Shaw Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Reviews
Interviews
Salaries
Users/Month