All Topics

Greedy

Make the locally optimal choice at each step to find the global optimum

0/40 solved

Interval Scheduling

Maximize non-overlapping intervals or merge overlapping ones

O(n log n) O(n)

Approach

Sort intervals by start or end time. Process greedily: for merging, extend current interval if overlapping. For selection, pick intervals that end earliest. For counting overlaps, track active intervals.

How to Recognize

1

Problem involves intervals with start and end times

2

Need to merge, count, or select non-overlapping intervals

3

Phrases like 'merge intervals', 'non-overlapping', 'minimum rooms'

4

Sort by start or end time is the key first step

Pro Tips

To maximize non-overlapping: sort by end time, greedily pick earliest-ending

To merge: sort by start time, extend end if overlapping

To find minimum platforms/rooms: use sweep line or min-heap approach

8

Total

1

Easy

7

Medium

0

Hard

Time

O(n log n)

Space

O(n)