LeetCode 1229: Meeting Scheduler Solution
Master LeetCode problem 1229 (Meeting Scheduler), a medium challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.
1229. Meeting Scheduler
Problem Explanation
Explanation
The problem asks us to find a common meeting time slot of a specified duration between two schedules of meetings. We need to find the earliest possible time slot that satisfies the duration requirement.
To solve this problem, we can follow these steps:
- Merge the schedules of both persons.
- Sort the merged schedule based on the start time.
- Iterate through the sorted schedule to find a time slot that satisfies the duration requirement.
Time Complexity: O(n log n), where n is the total number of slots in both schedules. Space Complexity: O(n), where n is the total number of slots in both schedules.
Solution Code
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Solution {
public List<Integer> minAvailableDuration(int[][] slots1, int[][] slots2, int duration) {
List<int[]> merged = new ArrayList<>();
for (int[] slot : slots1) {
merged.add(slot);
}
for (int[] slot : slots2) {
merged.add(slot);
}
Collections.sort(merged, (a, b) -> a[0] - b[0]);
for (int i = 0; i < merged.size() - 1; i++) {
int[] current = merged.get(i);
int[] next = merged.get(i + 1);
if (next[0] - current[1] >= duration) {
return List.of(current[1], current[1] + duration);
}
}
return new ArrayList<>();
}
}Try It Yourself
Loading code editor...
Related LeetCode Problems
Frequently Asked Questions
How to solve LeetCode 1229 (Meeting Scheduler)?
This page provides optimized solutions for LeetCode problem 1229 (Meeting Scheduler) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.
What is the time complexity of LeetCode 1229 (Meeting Scheduler)?
The time complexity for LeetCode 1229 (Meeting Scheduler) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.
Can I run code for LeetCode 1229 on DevExCode?
Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 1229 in Java, C++, or Python.