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

Patterns and custom keys

8 questions. Covers Custom keys: equals, hashCode and pair hashing.

Questions 1 to 5 of 8

  1. 1. Why does the isomorphic check use two maps instead of one?
  2. 2. What does this program print? ``cpp #include <iostream> #include <string> #include <unordered_map> using namespace std; bool isIsomorphic(const string& s, const string& t) { if (s.size() != t.size()) return false; unordered_map<char, char> sToT; unordered_map<char, char> tToS; for (size_t i = 0; i < s.size(); ++i) { char a = s[i]; char b = t[i]; auto forward = sToT.find(a); if (forward != sToT.end() && forward->second != b) return false; auto backward = tToS.find(b); if (backward != tToS.end() && backward->second != a) return false; sToT[a] = b; tToS[b] = a; } return true; } int main() { cout << boolalpha; cout << isIsomorphic("abab", "cdcd") << " " << isIsomorphic("abc", "xxy") << "\n"; } ``
  3. 3. What is wrong with the line that splits the sentence? ``cpp #include <string> #include <vector> using namespace std; int main() { string text = "dog cat cat dog"; vector<string> words = text.split(' '); return static_cast<int>(words.size()); } ``
  4. 4. Does the pattern abba match the sentence dog cat cat fish? True or false?
  5. 5. Inside the check, why does the lesson look up keys with find instead of map[key]?

5 question(s) left on this page.