FunctionRacerProblemsRace

Fewest Door Visits

MediumGreedyPython, JavaScript, TypeScript, Java, C++

Each item of windows is [start, end]: a delivery that can arrive at any minute from start to end, both included. You can be at the door at minutes of your choice; a visit at minute t receives every delivery whose window contains t, that is start <= t <= end. Return the fewest visits needed so that every delivery is received. Return 0 if windows is empty. The windows may be given in any order, and start == end is allowed.

Example 1

windows [[1,5],[4,8],[7,10],[9,12]]
returns 2

A visit at minute 5 receives [1, 5] and [4, 8]; a visit at minute 10 receives [7, 10] and [9, 12]. No single minute lies in all four windows.

Example 2

windows [[0,2],[3,5],[6,8]]
returns 3

The three windows share no minute, so each needs its own visit.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems