◀ THE GRIND — INTERVALS

Meeting Rooms

The drill: A single person's day is booked as a list of meetings. Decide whether they can attend every one of them — that is, whether any two ever overlap.

THE BRIEFING — THE FULL DRILL, IN MY OWN WORDS

One person's schedule for a day arrives as a list of meetings, each with a start and an end time. The job is to say whether that single person could physically sit through every meeting on the list.

Attending everything is possible only when no two meetings ever overlap in time — a meeting ending at the exact moment another begins is fine, since nothing actually collides.

The answer is a single yes-or-no: true if the whole day can be attended start to finish, false the moment any pair of meetings genuinely conflicts.

EX 01
intervals = [[1, 5], [6, 10], [11, 15]]
true
CLEAN GAPS BETWEEN EVERY MEETING
EX 02
intervals = [[1, 5], [4, 10]]
false
ONE MEETING STARTS BEFORE THE OTHER ENDS
EX 03
intervals = [[5, 10]]
true
SINGLE MEETING
THE HINTS — TAKE ONLY WHAT YOU NEED
HINT 1 THE NUDGE

Two meetings conflict only if one starts before the other ends. Checking every pair works, but a cheap reordering turns 'any two might conflict' into 'only neighbors can conflict'.

HINT 2 THE STRUCTURE

Sort the meetings by start time. After sorting, any conflict must show up between two meetings that sit next to each other in that order.

HINT 3 ONE STEP FROM THE ANSWER

Sort by start, then walk the list once: if any meeting's start time is less than the previous meeting's end time, the day is impossible — return false. If the walk finishes clean, return true.

COACH'S BOARD — THE PATTERN, STEP BY STEP
SORT AND SCANPATTERN · GREEDY — SORT BY STARTmeetings = [5,10], [0,3], [3,6]
[0,3]
[3,6]
[5,10]
STEP 1

Meetings [5,10], [0,3], [3,6]. Sort by start first — a conflict can only ever hide between neighbors: [0,3], [3,6], [5,10].

STEP 1 / 5 · ← → WORK TOO
THE SPLITS — TWO PACES, TWO LANGUAGES
grind/meeting-rooms.pyRACE PACE
LANG ▸
PACE ▸
class Solution:
    def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
        ivs = sorted(intervals, key=lambda iv: iv[0])
        for i in range(1, len(ivs)):
            if ivs[i][0] < ivs[i - 1][1]:
                return False
        return True
TIME O(N LOG N)SPACE O(1)PYTHON · RACE PACE · 7 LN

✓ CHIP-TIMED — ALL 4 SOLUTIONS RAN GREEN AGAINST SELF-AUTHORED CASES IN CI · JDK 21 · CPYTHON 3.12 · NOTHING PUBLISHES RED