Match specific pattern
Submissions: 4025   Accuracy:

52.24%

  Difficulty: Easy   Marks: 2
Associated Course(s):   Placement 100

Given a dictionary of words and a pattern. Every character in the pattern is uniquely mapped to a character in the dictionary. The task is to complete a function findMatchedWords(dict,pattern) that returns a vector of strings matching with given pattern. The function takes two argument the first argument is an array of strings dict which denote the dictionary and the second argument is the pattern to match.

Input:
The first line of input contains an integer T denoting the number of test cases. Each testcase contains 3 lines. The first line contains an integer N denoting the number of strings in the dictionary,second line N space separated strings denoting the strings of the dictionary. The third line contains pattern.

Output:
The output for each test case will be the space separated strings that matches the given pattern in lexicographical order.

User Task:
Since this is a functional problem you don't have to worry about input, you just have to complete the function findMatchedWords()

Constraints:
1 <= T <= 100
1 <= N <= 10

Input
1
4
abb abc xyz xyy
foo

Output
abb xyy

Explanation
Testcase 1: In the above test case xyy and abb have same character at index 1 and 2 like the pattern.


 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.