Topics/Intervals/Sort by start

Key idea

Sort by start

Sort by start is a core idea inside Intervals: a mental checklist item you should be able to explain and apply without looking it up.

IntervalsPatternsKey idea

When to use it

Keep Sort by start in mind whenever you open a intervals question — it often decides your first data structure or loop structure.

How it works

  1. Define Sort by start in your own words using the Intervals vocabulary.
  2. Connect it to at least one pattern on this topic: Merge intervals, Insert interval.
  3. Find where it shows up in the lesson sections and in a practice problem.
  4. Explain a failure mode if you ignore Sort by start (wrong answer or worse complexity).

Solution

Reference implementation in C#, Python, Java, JavaScript, and C++.

Exact solutionSort by start

Why interviewers care

Strong candidates narrate ideas like Sort by start while coding — it proves understanding, not memorization.

Drill Sort by start with Intervals problems — filter the bank and solve 2–3 Easy/Medium items while saying the invariant out loud.

Watch-outs

  • !Inclusive vs exclusive ends
  • !Unsorted input assumptions

Practice this

Related Intervals problems — open any one and apply Sort by start.

Search bank →

More under Intervals

← Back to Intervals lesson