FunctionRacerProblemsRace

Most Workshops Before Their Deadlines

HardGreedyPython, JavaScript, TypeScript, Java, C++

Workshop i takes hours[i] hours of continuous work and must be finished no later than hour closes[i]. You start at hour 0 and work on workshops one at a time, one after another without overlap, in any order you choose; finishing exactly at a workshop's closing hour is fine. You may skip any workshops. Return the largest number of workshops you can finish on time. Return 0 for an empty list.

Example 1

hours [10,20,100,200]
closes [20,130,125,320]
returns 3

Do the 10-hour workshop (done at 10, closes 20), then the 100-hour one (done at 110, closes 125), then the 20-hour one (done at 130, closes 130). The 200-hour one cannot fit with those three, and no set of four works.

Example 2

hours [5,5,5]
closes [5,10,15]
returns 3

Done in order, the workshops finish at hours 5, 10 and 15, each exactly at its closing hour.

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