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 | vector<vector<int>> solution(const vector<vector<int>>& spans, |
| 2 | vector<int> fresh) { |
| 3 | |
| 4 | vector<vector<int>> ans; |
| 5 | |
| 6 | int i = 0; |
| 7 | int n = spans.size(); |
| 8 | |
| 9 | while (i < n && spans[i][1] < fresh[0]) { |
| 10 | ans.push_back(spans[i]); |
| 11 | i++; |
| 12 | } |
| 13 | |
| 14 | while (i < n && spans[i][0] <= fresh[1]) { |
| 15 | fresh[0] = min(fresh[0], spans[i][0]); |
| 16 | fresh[1] = max(fresh[1], spans[i][1]); |
| 17 | i++; |
| 18 | } |
| 19 | |
| 20 | ans.push_back(fresh); |
| 21 | |
| 22 | while (i < n) { |
| 23 | ans.push_back(spans[i]); |
| 24 | i++; |
| 25 | } |
| 26 | |
| 27 | return ans; |
| 28 | } |
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.