B from A
Practice
4.3 (16 votes)
Algorithms
String searching
String algorithms
Problem
85% Success 1824 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given two strings \(A\) and \(B\) of length \(N\) and \(M\) respectively consisting of lowercase English letters. You can make several strings using characters from \(A\). If you use any character of \(A\) to make the string, that character will be removed from \(A\).

That means if you select an integer \(i\) from \(1\) to the length of the string \(A\) and use \(A_i\), then the character \(A_i\) will be removed and the string length gets reduced by \(1\), the indices of characters to the right of the deleted one also get reduced by \(1\).

Find the maximum number of strings you can make the same as that of \(B\).

Input format

  • The first line contains an integer \(T\) denoting the number of test cases.
  • The first line of each test case contains two space-separated integers \(N\) and \(M\).
  • The second line of each test case contains the string \(A\).
  • The third line of each test case contains the string \(B\).

Output format

For each test case, print the maximum number of strings you can make the same as that of \(B\).

Constraints

\(1 \leq T \leq 10 \\ 1 \leq N, M \leq 10^5 \\ \text{A and B contains lowercase English letters}\)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
4 votes
Tags:
String SearchingAlgorithmsReal worldString Algorithms
Points:20
51 votes
Tags:
Ad-HocApprovedEasyOpenString ManipulationTwo pointer
Points:20
4 votes
Tags:
AlgorithmsEasyString Manipulation