Skip to main content
Back to problems
Leetcode
Medium
Arrays
Greedy
Intervals
Google
Reschedule Meetings For Maximum Free Time II

Move at most one meeting to maximize the longest continuous free time inside the event day.

Acceptance 100%
Problem Statement

Problem

You are given a day of length eventTime and a list of non-overlapping meetings scheduled within that day. Each meeting is represented by its start and end time, and no two meetings overlap.

You are allowed to reschedule at most one meeting by moving it to a different free time slot, as long as:

  • the moved meeting keeps the same duration,
  • meetings remain non-overlapping,
  • all meetings stay within [0, eventTime].

Your goal is to maximize the length of the longest continuous free interval after the rescheduling.

Return the maximum free-time length you can achieve.

Notes

  • You may also choose not to move any meeting.
  • The meetings are already sorted by start time and do not overlap.
  • If a meeting is moved, it may be placed anywhere that fits, including before the first meeting, between two meetings, or after the last meeting.

Input Format

  • eventTime: integer length of the day.
  • meetings: array of intervals [[start1, end1], [start2, end2], ...] sorted by start time.
  • Each interval denotes a meeting with duration end - start.

Output Format

  • Return a single integer: the maximum possible length of the longest free interval after moving at most one meeting.

Constraints

  • 0 <= start < end <= eventTime
  • Meetings are pairwise non-overlapping and sorted by start time.
  • At most one meeting may be moved.
  • The meeting duration must remain unchanged after moving.
  • All times are integers.
Examples
Sample cases returned by the problem API.

Example 1

Input

eventTime = 10
meetings = [[1,3],[6,7]]

Output

5

Explanation

The free gaps are [0,1], [3,6], and [7,10]. Moving the meeting [6,7] into the gap [0,1] is impossible because it is too short, but moving [1,3] into [7,10] leaves a merged free interval [0,6] of length 6? Not all placements are valid due to meeting durations. The best valid arrangement is to move [1,3] into [7,9], leaving free time [0,6] of length 6. The maximum longest free interval is 6.

Example 2

Input

eventTime = 8
meetings = [[1,2],[4,6]]

Output

4

Explanation

Move the meeting [1,2] to [6,7]. Then the free intervals become [0,1], [2,4], and [7,8], so the longest free interval is length 2. A better move is to move [4,6] to [0,2], which leaves [2,8] as a continuous free interval of length 6? That placement overlaps with the other meeting, so it is invalid. The best achievable longest free interval is 4.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.