Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created March 24, 2025 18:16
Show Gist options
  • Save Ifihan/b038b6ffcec656fa067632914e7b414b to your computer and use it in GitHub Desktop.
Save Ifihan/b038b6ffcec656fa067632914e7b414b to your computer and use it in GitHub Desktop.
Count Days Without Meetings

Question

Approach

To solve the problem, I sorted all the meeting intervals by their start day and merged any overlapping ones to avoid double-counting days. After merging, I calculated the total number of unique meeting days by summing the length of each merged interval. Finally, I subtracted the total meeting days from the given number of days to get the count of days when the employee is available but has no meetings.

Implementation

class Solution:
    def countDays(self, days: int, meetings: List[List[int]]) -> int:
        meetings.sort()
        merged = []
        
        for start, end in meetings:
            if not merged or merged[-1][1] < start:
                merged.append([start, end])
            else:
                merged[-1][1] = max(merged[-1][1], end)

        meeting_days = sum(end - start + 1 for start, end in merged)
        return days - meeting_days

Complexities

  • Time: O(nlogn)
  • Space: O(n)
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment