Smallest KMP SOLUTION
Smallest KMP Gourmet specialist has a string S. He likewise has another string P, called design. He needs to discover the example in S, however that may be unthinkable. Thusly, he is eager to reorder the characters of S so that P happens in the subsequent string (a re-arranged word of S) as a substring.
Since this issue was excessively hard for Chef, he chose to ask you, his virtuoso companion, for help. Would you be able to discover the lexicographically littlest re-arranged word of S that contains P as substring?
Note: A string B is a substring of a string An if B can be gotten from A by erasing a few (conceivably none or all) characters from the earliest starting point and a few (potentially none or all) characters from the end.
The primary line of the info contains a solitary number T indicating the quantity of experiments. The portrayal of T experiments follows.
The main line of each experiment contains a solitary string S.
The subsequent line contains a solitary string P.
For each experiment, print a solitary line containing one string ― the littlest re-arranged word of S that contains P.
S and P contain just lowercase English letters
there is at any rate one re-arranged word of S that contains P
Subtask #1 (20 focuses): |S|≤1,000
Subtask #2 (80 focuses): |S|≤105
otherwise known as
CODE Python3.6 :
for i in range(min(n1,n2)):
for i in range(t):
for k in pat:
remd=[0 for i in range(26)]
for k in st:
if k not in dicp or dicp[k]==0:
if len(pat)>1 and cmpr(pat+pat,pat+pat)==1:
for k in range(tmp+1):
for k in range(tmp+1,26):
for k in range(tmp):
for k in range(tmp,26):