Practice/Google/Leetcode 3439. Reschedule Meetings for Maximum Free Time I
CodingOptional
You are managing a schedule for an event that spans from time 0 to time eventTime. During this period, there are n non-overlapping meetings already scheduled, where each meeting i occupies the time interval [start_i, end_i].
You have the ability to reschedule up to k meetings. When you reschedule a meeting, you must:
[0, eventTime]Your goal is to maximize the length of the longest continuous block of free time in the schedule after optimally rescheduling up to k meetings.
Return the maximum possible length of a continuous free time block.
[0, eventTime] after reschedulingk meetings0 <= n <= 100,000 (number of meetings)1 <= eventTime <= 1,000,000,0000 <= k <= n0 <= start_i < end_i <= eventTime for all meetingsO(n) or O(n log n)O(n)Example 1:
Input: meetings = [[1, 3], [5, 7]], eventTime = 10, k = 1 Output: 6 Explanation: By moving the second meeting [5, 7] to [4, 6], we create a gap from [6, 10] of length 4. Alternatively, moving it to the end [8, 10] creates a gap [1, 8] of length 6 (after removing the first meeting's impact). The optimal strategy creates a 6-unit gap.
Example 2:
Input: meetings = [[2, 4], [6, 8]], eventTime = 10, k = 0 Output: 2 Explanation: Without moving any meetings, we have gaps [0, 2], [4, 6], and [8, 10], each of length 2.
Example 3:
Input: meetings = [[0, 5]], eventTime = 10, k = 1 Output: 10 Explanation: Since we can move the only meeting, we can shift it to create a 10-unit gap by compressing it to one end.