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 | int solution(const vector<vector<int>>& times) { |
| 2 | |
| 3 | int n = times.size(); |
| 4 | |
| 5 | vector<int> starts(n, 0); |
| 6 | vector<int> ends(n, 0); |
| 7 | |
| 8 | for (int i = 0; i < n; i++) { |
| 9 | starts[i] = times[i][0]; |
| 10 | ends[i] = times[i][1]; |
| 11 | } |
| 12 | |
| 13 | sort(starts.begin(), starts.end()); |
| 14 | sort(ends.begin(), ends.end()); |
| 15 | |
| 16 | int rooms = 0; |
| 17 | int ans = 0; |
| 18 | int j = 0; |
| 19 | |
| 20 | for (int i = 0; i < n; i++) { |
| 21 | |
| 22 | while (j < n && ends[j] <= starts[i]) { |
| 23 | rooms--; |
| 24 | j++; |
| 25 | } |
| 26 | |
| 27 | rooms++; |
| 28 | ans = max(ans, rooms); |
| 29 | } |
| 30 | |
| 31 | return ans; |
| 32 | } |
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.