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

Anagrams and consecutive runs

8 questions. Covers Longest consecutive sequence with a hash set.

Questions 1 to 5 of 8

  1. 1. The countKey function from the lesson writes each letter that appears, then its count, then a comma. What key does it build for banana?
  2. 2. In the longest-run method, why does the loop skip a value x when x - 1 is in the set?
  3. 3. Which pairs of words are anagrams of each other? Pick all that apply.

    Pick every answer that is true.

  4. 4. Which statements about longestRun in the lesson's first example are true? Pick all that apply.

    Pick every answer that is true.

  5. 5. What does this program print? ``cpp #include <algorithm> #include <iostream> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { unordered_map<string, vector<string>> groups; for (const string w : {"tea", "ate", "bat", "tab", "cat"}) { string key = w; sort(key.begin(), key.end()); groups[key].push_back(w); } cout << groups.size() << " " << groups["aet"].size() << " " << groups["abt"].back() << "\n"; } ``

5 question(s) left on this page.