forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC1229.cpp
More file actions
executable file
·34 lines (29 loc) · 750 Bytes
/
LC1229.cpp
File metadata and controls
executable file
·34 lines (29 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
Problem Statement: https://leetcode.com/problems/meeting-scheduler/
Time: O(m • log m + n • log n)
Space: O(1)
Author: Mohammed Shoaib, github.com/Mohammed-Shoaib
*/
class Solution {
public:
vector<int> minAvailableDuration(vector<vector<int>>& slots1, vector<vector<int>>& slots2, int duration) {
int m, n, i, j;
m = slots1.size();
n = slots2.size();
i = j = 0;
sort(slots1.begin(), slots1.end());
sort(slots2.begin(), slots2.end());
while (i < m && j < n) {
int beg, end;
beg = max(slots1[i][0], slots2[j][0]);
end = min(slots1[i][1], slots2[j][1]);
if (beg + duration <= end)
return {beg, beg + duration};
else if (slots1[i][1] < slots2[j][1])
i++;
else
j++;
}
return {};
}
};