Meeting Rooms I — control flow
flowchart TD
S["<b>i · sort</b><br/>intervals.sort(key=x[0])"]
--> L{"<b>ii · next pair?</b><br/>i = 1…n-1"}
L -->|"yes"| C{"<b>iii · overlap?</b><br/>intervals[i][0] < intervals[i-1][1]?"}
C -->|"yes"| F["<b>iv · return false</b>"]
C -->|"no"| L
L -->|"done"| T["<b>v · return true</b>"]
classDef start fill:#f5efe1,stroke:#6a8a4f,stroke-width:2px,color:#1a1915;
classDef decision fill:#fdecd3,stroke:#c2410c,stroke-width:2px,color:#1a1915;
classDef ok fill:#e7efd9,stroke:#587640,stroke-width:2px,color:#1a1915;
classDef bad fill:#f5d4cf,stroke:#991b1b,stroke-width:2px,color:#1a1915;
class S start
class L,C decision
class T ok
class F bad-
Sort by start
Overlapping meetings become adjacent, so we can check with a one-pass loop.
-
Iterate pairs
Walk from index 1 to `n-1` comparing `intervals[i]` with `intervals[i-1]`.
-
Overlap check
`intervals[i][0] < intervals[i-1][1]` — next meeting starts before previous ends.
-
Return false
First overlap detected → impossible to attend all.
-
Return true
Loop finished with no conflicts → every meeting is attendable.
Comments
Comments are disabled in this environment. Set
PUBLIC_GISCUS_REPO,PUBLIC_GISCUS_REPO_ID, andPUBLIC_GISCUS_CATEGORY_IDto enable.