Smallest KMP
Smallest KMP
Chef has a string . He also has another string , called pattern. He wants to find the pattern in , but that might be impossible. Therefore, he is willing to reorder the characters of in such a way that occurs in the resulting string (an anagram of ) as a substring.
Since this problem was too hard for Chef, he decided to ask you, his genius friend, for help. Can you find the lexicographically smallest anagram of that contains as substring?
Note: A string is a substring of a string if can be obtained from by deleting several (possibly none or all) characters from the beginning and several (possibly none or all) characters from the end.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single string .
- The second line contains a single string .
Output
For each test case, print a single line containing one string ― the smallest anagram of that contains .
Constraints
- and contain only lowercase English letters
- there is at least one anagram of that contains
Subtasks
Subtask #1 (20 points):
Subtask #2 (80 points):
Example Input
3
akramkeeanany
aka
supahotboy
bohoty
daehabshatorawy
badawy
Example Output
aaakaeekmnnry
abohotypsu
aabadawyehhorst
No comments:
Post a Comment
If you have any doubt . Please let me know