Katkat

Solve meeting-room scheduling and shortest paths

GoogleSoftware Engineer · Onsite

Last updated

This problem tests your ability to manage overlapping intervals using a priority queue and calculate the shortest path in a DAG representing dependencies.

Problem Statement

You are tasked with scheduling a set of meetings in a single conference room. Each meeting has a unique ID, a start time, and an end time. Additionally, some meetings have 'dependency' constraints: if meeting A is a prerequisite for meeting B, meeting B cannot start until meeting A has finished.

Task 1: Scheduling

Given a list of meetings (id, start, end), determine the minimum number of rooms required to host all meetings without overlap. If a room becomes free at time T, a new meeting can start at time T.

Task 2: Critical Path

Given a list of dependencies (prerequisite_id, meeting_id), identify the 'critical path'—the sequence of dependent meetings that results in the longest total duration. If there are no dependencies, return the duration of the longest single meeting.

Function Signature

def solve_scheduling(meetings, dependencies):
    # meetings: List of tuples (id, start, end)
    # dependencies: List of tuples (prereq_id, meeting_id)
    # Return: (min_rooms_needed, max_dependency_duration)

Constraints

  • 1 <= len(meetings) <= 10^4
  • 0 <= start < end <= 10^9
  • dependencies form a Directed Acyclic Graph (DAG).

Example

Input: meetings = [(1, 0, 5), (2, 2, 6), (3, 7, 10)] dependencies = [(1, 2)]

Output: (2, 9)

Explanation:

  • Room 1 hosts meeting 1 (0-5) and meeting 3 (7-10). Room 2 hosts meeting 2 (2-6). Total 2 rooms.
  • Dependency 1 -> 2: Meeting 1 duration (5) + Meeting 2 duration (4) = 9. Max path is 9.

Edge Cases

  • Empty meetings or dependencies.
  • Meetings with no dependencies.
  • Disconnected components in the dependency graph.

Hints

Hint 1

To find the minimum number of rooms, sort the meetings by start time and use a min-heap to keep track of the end times of meetings currently in progress.

Hint 2

For the critical path, represent the dependencies as an adjacency list and use memoized recursion or topological sort to find the longest path in the DAG.

Hint 3

Remember that the duration of a single meeting is `end - start`.

Follow-up questions

  • How would you modify your solution if the room availability had a transition time (e.g., 15 minutes of cleaning between meetings)?
  • What if you were asked to return the IDs of all meetings on the critical path instead of just the total duration?
  • How does the complexity change if you need to calculate the critical path across all possible independent chains of meetings?