Square PointOA #2
Suggested Products
Estimated MediumJudge-ready
Topics (AI-labelled)Trie & CodecBinary Search
You are given distinct product names and a search word. After each character of the search word is typed, output at most 3 lexicographically smallest products among all products matching the current prefix.
This site added the standard input/output protocol.
Input
The first line contains n m (1 ≤ n,m ≤ 1000); the second line contains n product names without whitespace; the third line contains the search word. Product names and the search word contain only lowercase English letters.
Output
Output one line for each non-empty prefix of the search word. The line lists at most 3 smallest matching products in lexicographic order; output - if nothing matches.
Example 1
Input:
4 4
abcd abba adbc abcc
abcd
Output:
abba abcc abcd
abba abcc abcd
abcc abcd
abcd
Example 2
Input:
3 1
b a ba
c
Output:
-
Example 3
Input:
4 2
ba bb bc bd
ba
Output:
ba bb bc
ba
Editorial
Loading solution…