CodeGround
DashboardProblemsInterviewsAssessmentsCourses
CodeGround
DashboardProblemsInterviewsAssessmentsCourses
The Technical Interview Course

0 of 170 lessons complete

  • When do two intervals conflict?
  • Absorbing into the block you are building
  • Three phases in one pass
  • Sorting by end, and why that is the greedy choice
  • Sweeping through time
  • Retrieval: start or end?

Intervals

52 / 170

Intervals/Lesson 6 of 6·About 44 min

Retrieval: start or end?

Two problems rebuilt cold, plus the one decision that separates these problems from each other.

Key idea

Which key, and why

Almost every interval problem is decided by this one choice, and the reason is always the same: sort by whatever the pass needs to compare against.

QuestionSort byBecause
Does anything conflictstartconflicts are with the previous interval
Merge overlapping onesstartconnections are between neighbors
Insert one into a sorted setalready sortedthe guarantee makes it linear
Keep as many as possibleendfinishing early frees the resource soonest
How many at onceneither, use eventsthe answer belongs to a moment

Tip

And the recurring decision

Whether touching counts as overlapping has come up in every lesson of this unit. It is decided by the problem, not by the technique, and it is the single most common reason an interval solution is off by exactly the cases you did not test.

Quick check· 5 min

Which key does this want?

Given a list of jobs with start and end times and one machine, you must report the largest number of jobs that could have been run. What should you sort by?

Problem· 15 min

Merge Intervals, from scratch

You have solved this one before. Rebuild it from scratch without looking at your old submission. If the approach does not come back within a few minutes, that is the signal that it needs another pass.

Problem· 20 min

Search in Rotated Sorted Array, from scratch

You have solved this one before. Rebuild it from scratch without looking at your old submission. If the approach does not come back within a few minutes, that is the signal that it needs another pass.

PreviousSweeping through time
NextCold recall

0 of 4 parts complete