Hard Accuracy: 35.12% Submissions: 13075 Points: 8
Given a list of contacts which exist in a phone directory and a query string str. The task is to implement search query for the phone directory. Run a search query for each prefix p of the query string str(i.e from index 1 to str length) that prints all the distinct recommended contacts which have the same prefix as our query (p) in lexicographical order. Please refer the explanation part for better understanding.
NOTE: If there is no match between query and contacts , print "0".
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains three lines. First line of each test case contains N i.e., number of contacts. Second line contains space separated all the contacts in the form of string. And third line contains query string.
For each test case, print each query result in new line. If there is no match between query and contacts, print "0".
By running the query on contact list, we get,
Suggestions based on "g" are: geeikistest geeksforgeeks geeksfortest
Suggestions based on "ge" are:
geeikistest geeksforgeeks geeksfortest
Suggestions based on "gee" are:
geeikistest geeksforgeeks geeksfortestSuggestions based on "geei" are:geeikistestNo Results Found for "geeip", So print "0".
No Results Found for "geeips", So print "0".