Dorms War Codeforces Solution | Codeforces Problem Solution 2022
Hosssam decided to sneak into Hemose's room while he is sleeping and change his laptop's password. He already knows the password, which is a string of length . He also knows that there are special letters of the alphabet: .
Hosssam made a program that can do the following.
- The program considers the current password of some length .
- Then it finds all positions () such that is one of the special letters.
- Then it deletes all of those positions from the password even if is a special character. If there are no positions to delete, then the program displays an error message which has a very loud sound.
Prof. Slim Codeforces Solution | Codeforces Problem Solution 2022
Dorms War Codeforces Solution | Codeforces Problem Solution 2022
Where is the Pizza? Codeforces Solution | Codeforces Problem Solution 2022
Very Suspicious Codeforces Solution | Codeforces Problem Solution 2022
Hemose on the Tree Codeforces Solution | Codeforces Problem Solution 2022
Jee, You See? Codeforces Solution | Codeforces Problem Solution 2022
For example, suppose the string is "abcdef" and the special characters are 'b' and 'd'. If he runs the program once, the positions and will be deleted as they come before special characters, so the password becomes "bdef". If he runs the program again, it deletes position , and the password becomes "def". If he is wise, he won't run it a third time.
Hosssam wants to know how many times he can run the program on Hemose's laptop without waking him up from the sound of the error message. Can you help him?
The first line contains a single integer () — the number of test cases. Then test cases follow.
The first line of each test case contains a single integer () — the initial length of the password.
The next line contains a string consisting of lowercase English letters — the initial password.
The next line contains an integer (), followed by distinct lowercase letters — the special letters.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print the maximum number of times Hosssam can run the program without displaying the error message, on a new line.
Join Now for Solution:-
No comments:
Post a Comment