Shubham Sourabhthe room · director's cutplain résumé
Room 04 · The Grind — Intervals

Meeting Rooms

EASY✓ CHIP-TIMEDLC #252 — FULL STATEMENT

The briefingthe full drill, in my own words

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.

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.

  • up to a few thousand meetings in one call
  • start and end times are non-negative integers
  • a meeting's end is never earlier than its own start
  • a meeting ending exactly when another starts is not a conflict
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 hintstake 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 boardthe 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 splitstwo paces, two languages

grind/meeting-rooms.py — RACE 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-TIMEDALL 4 SOLUTIONS RAN GREEN AGAINST SELF-AUTHORED CASES IN CI · JDK 21 · CPYTHON 3.12 · NOTHING PUBLISHES RED