Given courses where courses[i] = [duration_i, lastDay_i], find the maximum number of courses you can take. Each course must finish by its lastDay.
Sort by deadline. Greedily take each course; if total time exceeds deadline, replace the longest previously taken course if it is longer than current course.
- Sort by lastDay.
- Max-heap tracks durations of taken courses.
- For each course: add duration to time and heap.
- If time > lastDay: pop max duration from heap, subtract from time.
- Answer = heap.size().
- Time Complexity: O(N log N)
- Space Complexity: O(N)