Lexicographical String TCS CodeVita Previous Year Questions

TCS Codevita Coding Question

Question:

Little John jumbled up the order of the letters in our dictionary. Now, Jason uses this list to find the smallest lexicographical string that can be made out of this new order. Can you help him? You are given a string S that denotes the new order of the letter in the English Dictionary. You needs to print the smallest lexicographic string made from the given String S.

Constraints:

1<=T<=1000 J=26 1<=S<=100

Note:

All character in the String S,J are in lower case

Input Format:

The First line contains number of test cases T The second line contains the String J The third line contains the String S

Output Format:

Print new lexicographical single string in a new line.

Test Cases :

Test Case 1:

Input:
1
polikujmnhytgbvfredcxswqaz
abcd
Output:
Bdca

Test Case 2:

Input:
1
qwryupcsfoghjkldezvxbintma
ativedoc
Output:
Codevita

Answer :

T = int(input())
for I in range (0,T):
    S= input()
    J = input()
    List=[]
    for i in S:
        List.append(J.find(i))
    List.sort()
    for i in List:
        print(J[i],end='')

Leave a Reply

Your email address will not be published. Required fields are marked *