codekofi
← All problems

Problem 8

Easy

1 · Worked examples

0 / 4

Type an input and write what you think is the output . Each problem is converted to Web Assembly, so any possible input will show the corresponding output. 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
3 if (a.size() != b.size()) {
4 return false;
5 }
6
7 unordered_map<char, int> tally;
8
9 for (char c : a) {
10 tally[c]++;
11 }
12
13 for (char c : b) {
14
15 tally[c]--;
16
17 if (tally[c] < 0) {
18 return false;
19 }
20 }
21
22 return true;
23}

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.