Post

3430 Count Days Without Meetings

3430 Count Days Without Meetings

Count Days Without Meetings image

You are given a positive integer days representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array meetings of size n where, meetings[i] = [start_i, end_i] represents the starting and ending days of meeting i (inclusive).

Return the count of days when the employee is available for work but no meetings are scheduled.

**Note: **The meetings may overlap.

 

Example 1:

Input: days = 10, meetings = [[5,7],[1,3],[9,10]]

Output: 2

Explanation:

There is no meeting scheduled on the 4th and 8th days.

Example 2:

Input: days = 5, meetings = [[2,4],[1,3]]

Output: 1

Explanation:

There is no meeting scheduled on the 5th day.

Example 3:

Input: days = 6, meetings = [[1,6]]

Output: 0

Explanation:

Meetings are scheduled for all working days.

 

Constraints:

1
2
3
4
1 <= days <= 109
1 <= meetings.length <= 105
meetings[i].length == 2
1 <= meetings[i][0] <= meetings[i][1] <= days
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

class Solution:
    def countDays(self, days: int, meetings: List[List[int]]) -> int:

        meetings.sort(key=lambda x : (x[0], x[1]))
        print(meetings)

        count = -1
        start = 0
        end = 0
        for k in meetings:
            print(start, end, count)
            if end < k[0]:
                count += (end - start + 1)
                start = k[0]
                end = k[1]
            else:
                end = max(k[1], end)
        print(start, end, count)
        count += (end - start + 1)
        return days - count
        



This post is licensed under CC BY 4.0 by the author.