Merge Intervals Interview Question: Interview Schedule | Skilled.dev
Interview Question

Interview Scheduler

Imagine this — you landed your dream job at the perfect company. You've worked your way up and are now the lead engineer. It's your turn to start interviewing candidates, and you want to make sure they have an amazing experience.

You want the candidates to meet the entire team, but you realize it's really difficult to find a time that fits all schedules. So, you ask everyone to send you the start and end time of their meetings so you can combine them to determine all the overlapping time blocks. Knowing when the team is free will allow you to effectively schedule the interview process for the candidate.

You receive an array that contains start and end times for each person's meeting times. The items will be represented as 30-minutes blocks. For example, 10.5 corresponds to the time 10:30.

If meetings overlap, you want to merge them into a single window that encompasses the earliest start time and latest end time. The solution should contain an array of items where each item is the range for the start and end time of each merged interval of meetings.

Write a function mergeOverlappingIntervals that returns an array of intervals where the ones with overlapping start and end times are combined to a single interval.

 

Breakdown

Loading...

Table of Contents

Validate My Answer

  1. This question has quite a few cases to consider. Try to think through the possible ways these meeting times can appear.

  2. Does your solution combine meetings that touch at the same start and end time? Since there is no time off between them, they should still be combined to the same interval.

     
  3. If a meeting starts and ends during another meeting, they are part of the same interval. Make sure your code handles this.

  4. If multiple meetings overlap at any point, they should all be combined.

     
  5. You could solve this by comparing an item to all intervals in O(n2) time, but that's not the best path. The simplest solution is also the one with the best time complexity. You can solve this in O(n log n) time and O(n) space.

Loading...

Table of Contents

Test Results

Run your code and see results here...

/**
 * @param {List[map<str,int>]} intervals
 * @return {List[map<str,int>]}
 */
const mergeOverlappingIntervals = (intervals) => {
  // Your solution here
}
// Upgrade for full course access
// Upgrade for full course access

Interview Scheduler

You receive an array that contains start and end times for each person's meeting times. The items will be represented as 30-minutes blocks. For example, 10.5 corresponds to the time 10:30.

If meetings overlap, you want to merge them into a single window that encompasses the earliest start time and latest end time. The solution should contain an array of items where each item is the range for the start and end time of each merged interval of meetings.

Write a function mergeOverlappingIntervals that returns an array of intervals where the ones with overlapping start and end times are combined to a single interval.

 
/**
 * @param {List[map<str,int>]} intervals
 * @return {List[map<str,int>]}
 */
const mergeOverlappingIntervals = (intervals) => {
  // Your solution here
}
// Upgrade for full course access
// Upgrade for full course access