Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Problem

Meeting Rooms

LeetCode #252Easy
Sort by start · check neighbours overlap

Given an array of meeting time intervals, determine if a single person could attend all meetings — i.e. whether no two meetings overlap.

Asked atAmazonMetaMicrosoft
step 1 / 4
[0,3]
[2,5]
[6,8]
0
1
2
3
4
5
6
7
8
[0][1][2][3][4][5][6][7][8]
Sort by start, check neighbours
1sort meetings by start
2prevEnd ← meetings[0].end
3for cur in meetings[1:]:
4 if cur.start < prevEnd: return false
5 else: prevEnd ← cur.end
6return true
state
  • sorted[0,3] [2,5] [6,8]

line 1Can one person attend ALL meetings? They can iff no two meetings overlap. SORT by start time first — then a meeting can only clash with the one immediately before it.