523. Course Schedule III (Greedy + Heap)

MediumBinary SearchGreedyHeapSorting

Given courses as [duration, lastDay] pairs (a course must be taken continuously and must finish on or before its lastDay), starting from day 1 and taking courses one at a time, return the maximum number of courses you can complete. The input is a JSON array of [duration, lastDay] pairs.

Input: A JSON array of [duration, lastDay] pairs.

Output: Integer — the maximum courses taken.

Examples

Example 1
Input: [[100,200],[200,1300],[1000,1250],[2000,3200]]
Output: 3
Explanation: Three courses fit.
Example 2
Input: [[1,2],[2,3]]
Output: 2
Explanation: Both fit.
Example 3
Input: [[3,2],[4,3]]
Output: 0
Explanation: Neither fits its deadline.

Constraints

Asked by

AmazonMicrosoftGoogleMeta
Solve this problem in the editor →