Frontend School

Can Attend All Meetings

DSA
easy

Can Attend All Meetings

Easy
Intervals
Sorting

Overview

At Netflix, our teams often juggle multiple projects and meetings. Ensuring that team members can effectively manage their schedules without conflicts is crucial for productivity. This problem asks you to determine if a person can attend all scheduled meetings given a list of their proposed meeting time intervals.

What you need to do / Task

You are given an array of meeting time intervals, where each interval intervals[i] = [start, end] represents the start and end time of a meeting. Your task is to determine if a person could attend all meetings.

Specifically, you must:

  1. Implement a function canAttendMeetings that takes an array of intervals as input.
  2. Return true if the person can attend all meetings without any schedule conflicts.
  3. Return false if there is at least one pair of meetings that overlap.

Input & output

Input: intervals: An array of number[] where each inner array [start, end] represents a meeting's start and end time. start and end are non-negative integers.

Output: boolean: true if all meetings can be attended without overlap, false otherwise.

Clarifications

  • What defines an overlap? Two meetings [s1, e1] and [s2, e2] are considered to overlap if s1 < e2 and s2 < e1. This means if one meeting ends exactly when another begins (e.g., [1, 5] and [5, 8]), they do not overlap, and the person can attend both. If s1 == s2 and e1 == e2, they are considered overlapping.
  • Empty or single meeting list: If the input intervals array is empty or contains only one meeting, there are no overlaps, so the person can attend all meetings.

Examples

1

Example 1

Input:

intervals = [[0,30],[5,10],[15,20]]

Output:

false

Note:

The meeting [0,30] overlaps with [5,10] and [15,20]. A person cannot attend all meetings.

2

Example 2

Input:

intervals = [[7,10],[2,4]]

Output:

true

Note:

There are no overlapping meetings. The person can attend both.

3

Example 3

Input:

intervals = [[1,5],[5,8],[9,12]]

Output:

true

Note:

Meetings [1,5] and [5,8] do not overlap as one ends exactly when the other begins. Similarly, [5,8] and [9,12] do not overlap. All meetings can be attended.

Constraints

Constraints & assumptions

  • 0 <= intervals.length <= 10^4
  • intervals[i].length == 2
  • 0 <= start < end <= 10^6
  • All start and end times are non-negative integers.

What interviewers evaluate

  • Problem Understanding & Approach: Ability to identify the core problem (interval overlap detection) and devise an efficient strategy.
  • Algorithm Efficiency: Implementation of an algorithm with optimal time and space complexity for the given constraints.
  • Correctness: Handling of all test cases, including edge cases like empty input, single intervals, and touching intervals.
  • Code Quality: Writing clean, readable, and maintainable code with appropriate data structures and clear logic.

Loading editor...