Count Prefixes of a Given String
A prefix of s is a piece that starts at its first character (the empty piece does not appear in words). Return how many entries of words are a prefix of s. Equal entries are counted each time they appear.
Example 1
words ["a","b","c","ab","bc","abc"]
s "abc"
returns 3
a, ab, abc are prefixes.
Example 2
words ["a","a"]
s "aa"
returns 2
Both copies of a count.
Constraints
1 <= len(words) <= 20- Words and
shave 1 to 10 lowercase letters
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Defanging an IP AddressBeginner
- Determine if String Halves Are AlikeBeginner
- Find Words Containing CharacterBeginner
- Join the Non-Empty PartsBeginner
- Longest Vowel RunBeginner
- Longest Word in a SentenceBeginner
- Maximum Nesting Depth of ParenthesesBeginner
- Mirror CipherBeginner