oneby7

Intervals Merging and scheduling

509. Meeting Rooms

Easy

You are given an array intervals, where intervals[i] = [start, end] is a meeting that starts at time start and ends at time end. Return true if one person can attend every meeting, and false otherwise.

A person cannot be in two meetings at once. Two meetings clash when one starts before the other ends. A meeting may start at the moment another one ends, so [1,5] and [5,8] do not clash.

Example 1

Input: intervals = [[10, 12], [1, 5], [6, 10], [13, 14]]

Output: true

Explanation: In time order the meetings are [1,5], [6,10], [10,12] and [13,14]. [10,12] starts just as [6,10] ends, which is allowed, and no two others meet at all.

Example 2

Input: intervals = [[2, 9], [11, 15], [4, 6]]

Output: false

Explanation: [4,6] lies inside [2,9], so the person cannot be at both.

Example 3

Input: intervals = []

Output: true

Explanation: There are no meetings, so nothing can clash.

Check your understanding

Work out the answer for this input before you write any code.

intervals = [[6, 9], [2, 4], [4, 6]]

Constraints

  • 0 ≤ intervals.length ≤ 105
  • intervals[i].length = 2
  • 0 ≤ start < end ≤ 109

Clarifying questions

What you would ask an interviewer before writing any code.

Hints

Interview follow-ups

Runs in your browser
Code
Runs in your browser for now · some things may not work as expectedLn 1, Col 1

Article

Send feedback

Thank you for helping. We read every report and fix what is wrong.

How do you feel about oneby7?

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.