---
title: 'Intervals Most Important Patterns'
source: 'https://youtube.com/watch?v=wbeTbgxOtvc'
video_id: 'wbeTbgxOtvc'
date: 2026-08-04
duration_sec: 90
---

# Intervals Most Important Patterns

> Source: [Intervals Most Important Patterns](https://youtube.com/watch?v=wbeTbgxOtvc)

## Summary

This video explains the two fundamental sorting strategies for solving interval-based coding problems: sorting by start time and sorting by end time. It demonstrates how each strategy applies to detecting overlaps, merging intervals, and finding the maximum number of non-overlapping intervals, with a clear example showing why sorting by end time is optimal for the latter.

### Key Points

- **Interval problems defined** [00:01] — An interval is a start time and an end time. Problems give a list of unsorted intervals, and the first step is always to sort them.
- **Two sorting strategies** [00:14] — There are two sorting strategies: sort by start time or sort by end time. The choice depends on the problem.
- **Detecting overlaps with start sort** [00:27] — Sort by start time places overlaps next to each other. To detect an overlap, check if the next start is less than the previous end.
- **Merging intervals** [00:39] — When merging overlapping intervals, extend the merged end to the max of both ends. Example: 1-3 and 2-6 become 1-6.
- **Max non-overlapping intervals** [00:53] — Sorting by start time fails for finding the most non-overlapping intervals because an early-starting long interval blocks others. Sorting by end time works better.
- **Greedy choice with end sort** [01:06] — Sort by end time and always pick the interval that ends earliest, leaving the most room for others. This greedy choice is always optimal.
- **Summary of strategies** [01:18] — Sort by start for detecting overlaps and merging; sort by end for maximizing non-overlapping intervals.

## Transcript

Turns out, companies love asking problems about exactly this. Here are every interval coding question. An interval is just a start time and an end A problem hands you a list of these, totally unsorted. Every interval problem
first, then walk through in order. There are two sorting strategies, and which one you pick depends on the problem. Strategy one, sort by start time. This Now, overlaps sit right next to each other. To detect an overlap, check one
previous one ends? If next start is less than previous end, they overlap. That's how you check if any intervals overlap. Sort by start, combining overlapping intervals into one? Same sort, but instead of just
When two intervals overlap, extend the merged end to cover both. Take the max of both ends. So, 1 to 3 and 2 to 6 become 1 to 6. merging as you go. That's how you merge all overlapping intervals.
What if you want the most non-overlapping intervals? meetings in a day. Sort by start time fails here. earliest, but it runs all day long. It blocks everything else. You fit one
meeting instead of three. The fix? Sort by end time instead. Always pick the leaves the most room for whatever comes next. Greedy choice, always optimal. Sort by start gave you one meeting. Sort by end, three. Two strategies, that's
all there is to it. Sort by start for detecting overlaps and merging. non-overlapping count. Try these problems on Hello Interview. Link is in problems on Hello Interview. Link is in the pinned comment. Follow for more.
