Embercode
✕
Maps and Sets (C++)Quick quiz

Time store and top K

8 questions. Covers Top K frequent words: heap versus bucket sort.

Questions 1 to 5 of 8

  1. 1. Which statements about TimeMap are true? Select all that apply.

    Pick every answer that is true.

  2. 2. Which statements about the two top-K methods are true? Select all that apply.

    Pick every answer that is true.

  3. 3. What does this program print? ``cpp #include <algorithm> #include <iostream> #include <iterator> #include <string> #include <vector> struct Version { int time; std::string value; }; std::string get_upper(const std::vector<Version>& v, int t) { auto after = std::ranges::upper_bound(v, t, {}, &Version::time); if (after == v.begin()) return ""; return std::prev(after)->value; } int main() { std::vector<Version> theme = {{2, "light"}, {6, "dark"}}; std::cout << get_upper(theme, 1) << '|' << get_upper(theme, 5) << '|' << get_upper(theme, 6) << '\n'; } ``
  4. 4. What does this program print? ``cpp #include <iostream> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { int n = 8; unordered_map<string, int> counts = {{"the", 3}, {"and", 2}, {"cat", 1}, {"dog", 1}, {"bird", 1}}; vector<vector<string>> buckets(n + 1); for (const auto& [word, c] : counts) buckets[c].push_back(word); cout << buckets.size() << ' ' << buckets[1].size() << ' ' << buckets[4].size() << '\n'; } ``
  5. 5. A store has color set to red at time 1, blue at time 5 and green at time 9. What does get("color", 4) return?

5 question(s) left on this page.