• + 0 comments

    Just for information, follow my solution with O(N+M) complexity, where n is teh size of stringList and M is the size of query list

    function matchingStrings(stringList: string[],queries: string[]): number[]{ const MatchCountMap = new Map(); const frequences: number[] = [];

    for(const word of stringList){
        const wordCount = MatchCountMap.get(word) ?? 0;
        MatchCountMap.set(word,wordCount+1);
    }
    
    for (const word of queries){
      const wordCount = MatchCountMap.get(word)
        frequences.push(wordCount ?? 0)
    }
    return  frequences;
    

    }