Prefix Count

For this question, we ask you to compute the number of strings that conform to a given prefix. That is you will first be given a dictionary of words. Then you will be given a series of prefixes of words and you will be given a series of queries to return the number of words in the dictionary that contains that prefix. Each query will simply be a string which is asking for the number of words that contain the string.

Only lower-case English letters will be used.


1 <= words.length <= 100001

1 <= words[i] <= 10


Example 1:
Input: word = ["forgot", "for", "algomonster", "while"], prefix = ["fo", "forg", "algo"]
Output: ans = [2, 1, 1]

"forgot" and "for" have the prefix "fo", only "forgot" has "forg" and lastly only "algomonster" has the prefix "algo".



Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions