Skip to interview prep
Apexed

74. Activity Selection (Max Non-Overlapping Intervals)

MediumGreedy

Each activity is [start, end]. Return the maximum number of activities one person can do if they cannot overlap. An activity may start exactly when another ends.

Example 1

Input: intervals = [[1, 2], [3, 4], [0, 6], [5, 7], [8, 9], [5, 9]]
Output: 4

Constraints

  • 1 ≤ intervals.length ≤ 10⁵

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Activity Selection (Max Non-Overlapping Intervals) — coding interview practice — Apexed