FastPrepMeeting Rooms

Meeting Rooms

ByteDance logoByteDance● EasyNEW GRADPHONE SCREEN

Problem statement

You are given a list of meetings, intervals, where intervals[i] = [starti, endi]. A meeting takes up the time from starti up to, but not including, endi.

Return true if one person can attend every meeting, meaning no two meetings overlap. Otherwise return false.

Two meetings overlap when they share some moment of time. A meeting that ends at time t and another that starts at time t do not overlap.

Function

canAttendMeetings(intervals: int[][]) → boolean

Examples

Example 1

intervals = [[9,12],[13,15],[11,14]]return = false

The meetings [9, 12] and [11, 14] both take up the time from 11 to 12, so one person cannot attend both.

Example 2

intervals = [[4,7],[1,4],[7,10]]return = true

In start order the meetings are [1, 4], [4, 7], and [7, 10]. Each one starts exactly when the one before it ends, which is allowed.

Example 3

intervals = [[5,8]]return = true

There is only one meeting, so nothing can overlap.

Constraints

  • 1 <= intervals.length <= 5000
  • intervals[i].length == 2
  • 0 <= starti < endi <= 10^6

More ByteDance problems

See ByteDance hiring insights
Saved
public boolean canAttendMeetings(int[][] intervals) {
    // Write your code here.
}
Checking account…