Ok! That's a simple problem with a simple solution written in Python 3, but to not lose the habit, I am publicly exposing my solution here.
There is a collection of input strings and a collection of query strings. For each query string, determine how many times it occurs in the list of input strings.
Complete the function matchingStrings in the editor below. The function must return an array of integers representing the frequency of occurrence of each query string in strings.
matchingStrings has the following parameters:
- strings - an array of strings to search
- queries - an array of query strings
Solution
def matchingStrings(strings, queries):
return [strings.count(query) for query in queries]
That is it. With one single line, we are returning an array that counts how many queries appears in strings.
Top comments (0)