Course Schedule III

There are n different online courses numbered from 1 to n. You are given an array courses where courses[i] = [durationi, lastDayi] indicates that the i^th course should be taken continuously for durationi days and must be finished before or on lastDayi.

You will start on the 1^st day and you cannot take two or more courses simultaneously.

Return the maximum number of courses that you can take.

Example 1
Inputcourses = [[100,200],[200,1300],[1000,1250],[2000,3200]]
Output3
You can take the 1^st course, then the 3^rd course, then the 2^nd course, but the 4^th course would finish after its closing date.
Example 2
Inputcourses = [[1,2]]
Output1
The only course can be completed before or on its last day.

Constraints

  • 1 <= courses.length <= 10^4
  • 1 <= durationi, lastDayi <= 10^4

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate