You are viewing a single comment's thread. Return to all comments →
Mine in C++ using solution involving sorting, lower_bound, and upper_bound
std::vector<int> matchingStrings( std::vector<std::string> strings, const std::vector<std::string>& queries) { std::sort(strings.begin(), strings.end()); std::vector<int> result; result.reserve(queries.size()); for (const auto& query : queries) { auto lower = std::lower_bound(strings.begin(), strings.end(), query); auto upper = std::upper_bound(strings.begin(), strings.end(), query); int diff = (lower == strings.end()) ? 0 : std::distance(lower, upper); result.push_back(diff); } return result; }
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 →
Mine in C++ using solution involving sorting, lower_bound, and upper_bound