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.
Locked until you have predicted 3 outputs correctly.
| 1 | void walk(map<string, multiset<string>>& out, const string& at, |
| 2 | vector<string>& route) { |
| 3 | |
| 4 | auto& ahead = out[at]; |
| 5 | |
| 6 | while (!ahead.empty()) { |
| 7 | |
| 8 | string other = *ahead.begin(); |
| 9 | ahead.erase(ahead.begin()); |
| 10 | |
| 11 | walk(out, other, route); |
| 12 | } |
| 13 | |
| 14 | route.push_back(at); |
| 15 | } |
| 16 | |
| 17 | vector<string> solution(const vector<vector<string>>& tickets) { |
| 18 | |
| 19 | map<string, multiset<string>> out; |
| 20 | |
| 21 | for (const auto& t : tickets) { |
| 22 | out[t[0]].insert(t[1]); |
| 23 | } |
| 24 | |
| 25 | vector<string> route; |
| 26 | walk(out, "JFK", route); |
| 27 | |
| 28 | reverse(route.begin(), route.end()); |
| 29 | |
| 30 | return route; |
| 31 | } |
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.