Interval Problems
Intervals appear constantly in interviews. Merge overlapping intervals, insert intervals, and cover intervals with minimum points.
Lessons
1. Intro
The interval pattern
2. The Interval Pattern
Sort first, scan second
3. Problem - Merge Intervals
Combine overlapping
4. Merge Intervals - The Idea
Sort by start
5. Merge Intervals - Algorithm
Step by step
6. Merge Intervals - Walkthrough
Tracing the algorithm
7. Merge Intervals - Implementation
The code
8. Quiz: Merge Intervals
Test your understanding
9. Problem - Insert Interval
Add without overlap
10. Insert Interval - Algorithm
Three phases
11. Insert Interval - Implementation
The code
12. Lessons from Merge and Insert
Key patterns
13. Problem - Interval List Intersections
Two sorted lists
14. Interval Intersections - Algorithm
Two-pointer approach
15. Interval Intersections - Implementation
The code
16. Quiz: Interval Intersections
Apply the algorithm
17. Problem - Remove Covered Intervals
Eliminate redundancy
18. Remove Covered - Algorithm
Sort and track
19. Remove Covered - Implementation
The code
20. Problem - Minimum Intervals to Cover
Cover a range
21. Minimum Cover - Algorithm
Greedy extension
22. Minimum Cover - Implementation
The code
23. Quiz: Interval Covering
Apply the pattern
24. Why Sort by End Time?
The selection key
25. Quiz: Sort Order Choice
When to use which
26. Problem - Non-overlapping Intervals
Minimum removals
27. Non-overlapping - The Idea
Maximize to minimize
28. Non-overlapping - Implementation
The code
29. Problem - Meeting Rooms
Can attend all?
30. Meeting Rooms - Algorithm
Overlap detection
31. Meeting Rooms - Implementation
The code
32. Problem - Meeting Rooms II
Minimum rooms needed
33. Meeting Rooms II - Event Sweep
Start and end events
34. Meeting Rooms II - Implementation
The code
35. Quiz: Meeting Rooms
Event sweep understanding
36. The Sweep Line Pattern
Processing events
37. Problem - My Calendar I
Online interval insertion
38. My Calendar I - Algorithm
Linear vs balanced
39. My Calendar I - Implementation
The code
40. Interval Overlap Check
The formula
41. Quiz: Interval Overlap
Testing the formula
42. Comparing Interval Patterns
Know your problem type
43. What is Next
Looking ahead
44. Section Recap
What we learned