Description
Take maximum number of courses given duration and deadline for each. Courses must finish by deadline.
Examples
Input:
courses = [[100,200],[200,1300],[1000,1250],[2000,3200]]Output:
3Explanation:
Take 3 courses max.
Input:
courses = [[1]]Output:
1Explanation:
Minimal case with a single-element matrix.
Input:
courses = [[5,10],[4,6],[7,8],[2,3]]Output:
2Explanation:
Sort by deadline: [[2,3],[4,6],[7,8],[5,10]]. Take course [2,3] (finishes at time 2). Take course [4,6] (finishes at time 6). Cannot take [7,8] as it would finish at time 13, exceeding deadline 8. Cannot take [5,10] as it would finish at time 18, exceeding deadline 10. Maximum courses = 2.
Constraints
- •
1 ≤ courses.length ≤ 10⁴