Match specific pattern
Submissions: 4345   Accuracy:


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

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.

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.

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()

1 <= T <= 100
1 <= N <= 10

abb abc xyz xyy

abb xyy

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, generate link and share the link here.

to report an issue on this page.