#3169
Medium Algorithms Count days without meetings
Array Sorting
48.1% acceptance
Feb 24, 2026
779
19
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.
Solution
Rust
Time O(n log n)
Space O(1)
impl Solution {
pub fn count_days(days: i32, mut meetings: Vec<Vec<i32>>) -> i32 {
meetings.sort_unstable();
let mut covered = 0i32;
let mut cur_start = -1i32;
let mut cur_end = -1i32;
for m in &meetings {
if m[0] > cur_end + 1 {
if cur_end >= 0 {
covered += cur_end - cur_start + 1;
}
cur_start = m[0];
cur_end = m[1];
} else {
cur_end = cur_end.max(m[1]);
}
}
if cur_end >= 0 {
covered += cur_end - cur_start + 1;
}
days - covered
}
}