We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
A O(strings+queries) solution in C++ using unordered_map where all operations used below are at O(1) according to to implementation document.
vector<int>matchingStrings(vector<string>strings,vector<string>queries){unordered_map<string,int>frequency;vector<int>results;//counts all occurances of str in strings and populates the frequency mapfor(stringstr:strings)frequency[str]++;//writes out the queries occurances in resultfor(stringstr:queries)results.push_back(frequency[str]);returnresults;}
Cookie support is required to access HackerRank
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 →
A O(strings+queries) solution in C++ using unordered_map where all operations used below are at O(1) according to to implementation document.