codekofi
← All problems

Problem 8

Easy30 XP

1 · Worked examples

0 / 4

Give it an input and say what you think comes back. It compiles and runs for real, so a wrong guess still shows you the answer — probe as much as you like. Only correct predictions count.

solution()
returns

2 · Which problem is it?

Locked until you have predicted 4 outputs correctly.

The accepted solution

1bool solution(const string& a, const string& b) {
2 if (a.size() != b.size()) return false;
3 unordered_map<char, int> tally;
4 for (char c : a) {
5 tally[c]++;
6 }
7 for (char c : b) {
8 tally[c]--;
9 if (tally[c] < 0) return false;
10 }
11 return true;
12}

Names have been stripped. The signature is the only clue you get for free. Compiled as C++20 with the standard headers and using namespace std; already in scope.