# 1229. Meeting Scheduler

• Time: $O(\texttt{sort}(\texttt{slots1}) + \texttt{sort}(\texttt{slots2}))$
• Space: $O(\texttt{sort}(\texttt{slots1}) + \texttt{sort}(\texttt{slots2}))$
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 class Solution { public: vector minAvailableDuration(vector>& slots1, vector>& slots2, int duration) { sort(begin(slots1), end(slots1)); sort(begin(slots2), end(slots2)); int i = 0; // slots1's index int j = 0; // slots2's index while (i < slots1.size() && j < slots2.size()) { const int start = max(slots1[i][0], slots2[j][0]); const int end = min(slots1[i][1], slots2[j][1]); if (start + duration <= end) return {start, start + duration}; if (slots1[i][1] < slots2[j][1]) ++i; else ++j; } return {}; } }; 
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 class Solution { public List minAvailableDuration(int[][] slots1, int[][] slots2, int duration) { Arrays.sort(slots1, (a, b) -> a[0] - b[0]); Arrays.sort(slots2, (a, b) -> a[0] - b[0]); int i = 0; // slots1's index int j = 0; // slots2's index while (i < slots1.length && j < slots2.length) { final int start = Math.max(slots1[i][0], slots2[j][0]); final int end = Math.min(slots1[i][1], slots2[j][1]); if (start + duration <= end) return Arrays.asList(start, start + duration); if (slots1[i][1] < slots2[j][1]) ++i; else ++j; } return new ArrayList<>(); } } 
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 class Solution: def minAvailableDuration(self, slots1: List[List[int]], slots2: List[List[int]], duration: int) -> List[int]: slots1.sort() slots2.sort() i = 0 # slots1's index j = 0 # slots2's index while i < len(slots1) and j < len(slots2): start = max(slots1[i][0], slots2[j][0]) end = min(slots1[i][1], slots2[j][1]) if start + duration <= end: return [start, start + duration] if slots1[i][1] < slots2[j][1]: i += 1 else: j += 1 return []