Untitled

 avatar
unknown
plain_text
a year ago
946 B
7
Indexable
Question:
You are given a list of words and a list of queries. Each query is a prefix, and your task is to find out how many words in the list start with that prefix.

Input:
A list of words: List<String>
A list of queries: List<String>
Output:
A list of integers where each integer represents the count of words that start with the corresponding prefix in the list of queries.

Example:
Input:

kotlin
Copy code
val words = listOf("apple", "app", "apricot", "banana", "bat", "ball", "apex")
val queries = listOf("ap", "ba", "a", "bat")
Output:

kotlin
Copy code
val result = listOf(4, 3, 5, 1)
Explanation:

"ap" matches "apple", "app", "apricot", and "apex" (4 words)
"ba" matches "banana", "bat", and "ball" (3 words)
"a" matches "apple", "app", "apricot", "apex", and "banana" (5 words)
"bat" matches "bat" (1 word)
Constraints:
The number of words and queries can be up to 10^4.
The length of each word and query can be up to 100 characters.
Editor is loading...
Leave a Comment