You are viewing a single comment's thread. Return to all comments →
1. Time Complexity O(n + q)
2. Space Complexity O(n + q)
vector matchingStrings(const vector& strings, const vector& queries) {
unorderedmap<string, int> freqMap; for (const string& str : strings) { freqMap[str]++; } vector<int> results; for (const string& query : queries) { results.pushback(freqMap[query]); } return results;
}
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 →
1. Time Complexity O(n + q)
2. Space Complexity O(n + q)
vector matchingStrings(const vector& strings, const vector& queries) {
}