[Solution] Minimise LCS CodeChef Solution
Problem
Chef is given two strings and of length containing lowercase English letters.
Chef can rearrange both the strings in any way he wants. He wants to minimize the length of LCS (Longest Common Subsequence) of both the strings.
Find the minimum length of LCS of and if he optimally rearranges both the strings.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains an integer - denoting the length of and .
- The second line of each test case contains a string .
- The third line of each test case contains a string .
Output Format
For each test case, output the minimum length of LCS Chef can obtain.
👇👇👇👇👇
Explanation:
Test case 1: . It can be shown that no other rearrangement of the strings produces a smaller LCS.
Test case 3: . Note that multiple longest common subsequences exist for this arrangement. It can be shown that no other rearrangement of the strings produces a smaller LCS.
No comments:
Post a Comment