## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Minimise LCS CodeChef Solution

## Problem

Chef is given two strings $A$ and $B$ of length $N$ 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 $A$ and $B$ if he optimally rearranges both the strings.

### Input Format

• The first line of input will contain a single integer $T$, 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 $N$ - denoting the length of $A$ and $B$.
• The second line of each test case contains a string $A$.
• The third line of each test case contains a string $B$.

### Output Format

For each test case, output the minimum length of LCS Chef can obtain.

Solution Click Below:-  👉
👇👇👇👇👇

### Explanation:

Test case 1: $\mathrm{LCS}(\texttt{aaaa}, \texttt{aaab}) = \texttt{aaa}$. It can be shown that no other rearrangement of the strings produces a smaller LCS.

Test case 3: $\mathrm{LCS}(\texttt{acbed}, \texttt{gdefc}) = \texttt{c}$. 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.