Move one meeting to another valid time so that the longest continuous free time becomes as large as possible.
You are given a schedule of non-overlapping meetings within a fixed time horizon. You may reschedule at most one meeting to any other position as long as the meetings remain non-overlapping and preserve their durations. Your goal is to maximize the length of the longest continuous free time block in the resulting schedule.
Return the maximum possible length of a free interval after performing at most one rescheduling operation.
The meetings are typically represented as intervals sorted by start time, and the free time is the gaps between adjacent meetings as well as the time before the first meeting and after the last meeting.
Input Format
- An array of meeting intervals, where each interval is represented by its start and end time.
- A fixed overall time range may be implied by the schedule boundaries.
- The meetings are non-overlapping in the initial schedule.
Output Format
- Return a single integer: the maximum length of a continuous free time segment achievable after rescheduling at most one meeting.
Constraints
- Meetings do not overlap initially.
- If a meeting is moved, its duration must stay the same.
- The rescheduled meeting must still not overlap any other meeting.
- Time values are integers.
- The schedule size is small to moderate in interview settings; exact platform constraints may vary.
Example 1
Input
meetings = [[1,3],[6,7],[9,12]], totalTime = 15
Output
6
Explanation
The free gaps are [0,1], [3,6], [7,9], and [12,15], with lengths 1, 3, 2, and 3. By moving the meeting [6,7] into the gap [12,15], the gap [3,9] becomes continuous free time of length 6.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.