Complete the Most Training Courses Before Their Deadlines

Last updated: November 29, 2026

Quick Overview

Each internal training course has a duration and a last day by which it must be finished. Courses are taken one at a time starting on day 0. Return the maximum number of courses you can complete.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Each internal training course has a duration and a last day by which it must be finished. Courses are taken one at a time starting on day 0. Return the maximum number of courses you can complete.

A Google onsite scheduling question in an internal learning platform frame. The interviewer checks sorting by deadline plus a max-heap that swaps out the longest course when the schedule overflows.

What the Interviewer Expects
  • Sorts courses by deadline
  • Accumulates total time taken
  • Uses a max-heap of durations
  • Drops the longest course when over the deadline
  • Explains why swapping out the longest is safe
Key Topics to Cover
Max-Heap
Greedy
Scheduling
Sorting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if courses have different values?
  • Return which courses were taken
  • What if some courses have a release day too?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of (duration, last_day).
  • Courses run back to back from day 0; course finishes at time t must satisfy t <= last_day.
  • Output: maximum number of courses completed....
High-Level Design

Process courses by deadline ascending (earliest deadline first is optimal for a fixed set). Keep a max-heap of chosen durations and the running total time. Add each course: push its duration and add...


Submit Your Answer
Markdown supported