Given courses with duration and deadline, find max number of courses you can take.

Input: courses=[[100,200],[200,1300],[1000,1250],[2000,3200]] → Output: 3 Input: courses=[[1,2]] → Output: 1

Sort by deadline. Use a max-heap: greedily take each course; if taking it exceeds deadline, replace longest course taken so far.

public int scheduleCourse(int[][] courses) { Arrays.sort(courses, (a, b) -> a[1] - b[1]); PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder()); int time = 0; for (int[] c : courses) { pq.offer(c[0]); time += c[0]; if (time > c[1]) { time -= pq.poll(); } } return pq.size(); }