Sparse Arrays

  • + 0 comments

    Here is the typescript solution for the better time complexity and space complexity. The time complexity over here will be o(n + q). I have created a hash map for the faster retrival of the information: Python:

    def matchingStrings(strings, queries):
        strings_frequency = {}
        for string in strings:
            strings_frequency[string] = strings_frequency.get(string, 0) + 1
    
        return [strings_frequency.get(query, 0) for query in queries]