Greedy choices and intervals interview questions

Sorting intervals by start or end, sweeping through events, and greedy rules you can prove with an exchange argument.

5 quick facts

– interview-ready · 12 questions in this topic

– of 12 tried

Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.

Questions

  1. Combine overlapping bookings into blocksPredict
  2. Fewest bookings to cancel so none clashPick the fix
  3. How many rooms do the bookings need at once?Predict
  4. Add a booking to a sorted list of separate blocksPredict
  5. Can you hop to the last tile?Predict
  6. Fewest hops to the last tilePredict
  7. Where to start a delivery loop so the van never runs dryPredict
  8. Cut a string into the most chunks so no letter crosses a cutPredict
  1. Largest total of a contiguous runPredict
  2. When does a greedy choice work?Pick the fix
  3. Sort intervals by start or by end?Pick the fix
  4. Sweep-line thinkingPredict

Practise this topic

Flashcards · 22

Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.

Quick quiz · 12 questions

One exercise per question, checked as you go. Needs JavaScript.

Mock interview · 2 sets

Timed, out loud, then tick what you covered. Needs JavaScript.

Quick facts

Recall the answer first, then tap Show to check.

Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license