Number of Valid Words for Each Puzzle
With respect to a given puzzle string, a word is valid if both of the following conditions are satisfied:
wordcontains the first letter ofpuzzle.- For each letter in
word, that letter is inpuzzle.
For example, if the puzzle is "abcdefg", then valid words are "faced", "cabbage", and "baggage", while invalid words are "beefed" because it does not include 'a', and "based" because it includes 's', which is not in the puzzle.
Return an array answer, where answer[i] is the number of words in the given word list words that are valid with respect to the puzzle puzzles[i].
Example 1
Input
words = ["aaaa","asas","able","ability","actt","actor","access"], puzzles = ["aboveyz","abrodyz","abslute","absoryz","actresz","gaswxyz"]Output
[1,1,3,2,4,0]For the six puzzles, the counts of valid words are 1, 1, 3, 2, 4, and 0 respectively.
Example 2
Input
words = ["apple","pleas","please"], puzzles = ["aelwxyz","aelpxyz","aelpsxy","saelpxy","xaelpsy"]Output
[0,1,3,2,0]The valid-word counts for the five puzzles are 0, 1, 3, 2, and 0 respectively.
Constraints
- 1 <= words.length <= 10^5
- 4 <= words[i].length <= 50
- 1 <= puzzles.length <= 10^4
- puzzles[i].length == 7
- words[i] and puzzles[i] consist of lowercase English letters.
- Each puzzles[i] does not contain repeated characters.