A harbor traffic-control station keeps a short roster of registered beacon codes used to identify vessel classes. When a ship approaches, its transponder broadcasts a single signal string. A registered beacon code is "recognized" for that broadcast if the code's letters exactly match the beginning (a prefix) of the broadcast signal string. Given the roster of beacon codes and one broadcast signal, determine how many roster entries are recognized.
n, the number of registered beacon codes.n+1: one beacon code per line, each a non-empty string of lowercase English letters.s, a non-empty string of lowercase English letters.Print a single integer: the number of beacon codes that are a prefix of s.
Example 1
Input
6 a b c ab bc abc abc
Expected
3
Explanation
The broadcast is "abc". Among the roster codes, "a" is a prefix (yes), "b" is not, "c" is not, "ab" is a prefix (yes), "bc" is not, and "abc" matches exactly, which counts as a prefix (yes). That gives 3 recognized codes.
Example 2
Input
2 a a aa
Expected
2
Explanation
The broadcast is "aa". The roster lists "a" twice; "aa" starts with "a", so both occurrences are recognized independently, giving a count of 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →