You are viewing a single comment's thread. Return to all 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;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Sparse Arrays
You are viewing a single comment's thread. Return to all 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[] = [];
}