A sign-maker's workshop owns a stencil set: a collection of distinct lowercase letters, each stencil reusable as many times as needed within a single word. A word from the day's job list is called "paintable" if every letter that appears anywhere in it is one of the letters in the stencil set (a letter may repeat within the word; only its presence in the stencil set matters).
Given the stencil set and a list of n candidate words, count how many of the words are paintable.
Line 1: the string allowed, the stencil set — distinct lowercase English letters, with no repeats.
Line 2: an integer n, the number of candidate words.
Each of the next n lines contains one word made of lowercase English letters.
A single integer: the number of paintable words among the n candidates.
allowed <= 26, all characters distinct lowercase lettersExample 1
Input
ab 5 ad bd aaab baa badab
Expected
2
Explanation
The stencil set is {a, b}. Words "aaab" and "baa" use only letters a and b, so they are paintable. The words "ad", "bd", and "badab" each contain the letter 'd', which is not in the stencil set, so they are not paintable. The count is 2.
Example 2
Input
abc 6 a b c ab abc abcd
Expected
5
Explanation
The stencil set is {a, b, c}. The words "a", "b", "c", "ab", and "abc" use only those three letters and are paintable. "abcd" contains 'd', which is outside the stencil set, so it is excluded. The count is 5.
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 →