Skip to main content
LeetCode 630, Hard. Topics: Array, Greedy, Sorting, Heap (Priority Queue). View on LeetCode. Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:

Problem

There are n different online courses numbered from 1 to n. You are given an array courses where courses[i] = [duration_i, lastDay_i] indicate that the i_th course should be taken continuously for duration_i days and must be finished before or on lastDay_i. 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.

Examples

Constraints

  • 1 <= courses.length <= 10^4
  • 1 <= duration_i, lastDay_i <= 10^4

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026