Problem
LeetCode #252 — one-liner.
- Given meeting intervals, can one person attend all of them? Return
true/false.
Key insight
Adjacency after sorting.
- After sorting by start, overlapping meetings must be adjacent.
- So the check reduces to: does any meeting start before its predecessor ends?
Solution template
Two lines of logic.
intervals.sort(key=lambda x: x[0])
for i in range(1, len(intervals)):
if intervals[i][0] < intervals[i - 1][1]:
return False
return TrueComplexity
Sort dominates.
- Time
O(n log n)— sort; the scan is O(n). - Space
O(1)— in-place sort, no extra structure.
Edge cases
Three to remember.
- 0 or 1 meetings → trivially
true. [1,2]+[2,3]— half-open: no conflict (2 < 2is false). Closed: conflict (≤).- All meetings at the same time → first pair already conflicts.
Comments
Comments are disabled in this environment. Set
PUBLIC_GISCUS_REPO,PUBLIC_GISCUS_REPO_ID, andPUBLIC_GISCUS_CATEGORY_IDto enable.