← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026

Summary

Amazon SWE interview with a scheduling/greedy algorithm problem. The question had a clean problem statement but the O(n log n) correctness argument took more thought than I expected.

Questions Asked (1)

Q1

Given a set of tasks each with a positive duration and a deadline, you can run only one task at a time in any order. What is the maximum number of tasks you can complete before their respective deadlines, and can you describe an O(n log n) algorithm with a correctness argument?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew this was a greedy problem pretty fast but fumbled explaining WHY the greedy choice is safe.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem as scheduling to maximize the number of on-time tasks, then propose a greedy algorithm using a max-heap to track selected tasks. Sort tasks by deadline, add each task's duration to the heap, and if the total time exceeds the current deadline, remove the longest task. This yields an O(n log n) solution; argue correctness via an exchange argument showing that at each step the greedy choice is safe.

Pro tip: Emphasize that the algorithm maintains a set of tasks that can be completed by the current deadline, and removing the longest task when over capacity is optimal because it frees the most time for future tasks. This demonstrates a deep understanding of greedy exchange arguments, which Amazon values.

1. Clarify the problem

Restate the problem: given n tasks with durations and deadlines, schedule them sequentially to maximize the number completed by their deadlines. Confirm that tasks are non-preemptive and can be done in any order.

2. Propose a greedy strategy

Sort tasks by deadline. Iterate through tasks, adding each to a max-heap (by duration) and accumulating total time. If total time exceeds the current task's deadline, remove the task with the largest duration from the heap and subtract its duration from total time.

3. Analyze complexity

Sorting takes O(n log n). Each task is inserted and possibly removed from the heap once, each operation O(log n). Total time O(n log n), space O(n).

4. Prove correctness

Use an exchange argument: at each step, the heap contains a maximum-size subset of tasks that can be completed by the current deadline. If adding a task causes infeasibility, removing the longest task yields a feasible set of the same size, and any optimal solution can be transformed to include this choice without reducing the count.

5. Discuss edge cases and trade-offs

Consider tasks with equal deadlines, zero durations (if allowed), and the case where all tasks can be completed. Mention that the algorithm is optimal and efficient, but if tasks had weights, a different approach (e.g., dynamic programming) would be needed.

Key Points to Mention

  • Greedy algorithm with sorting by deadline and max-heap for durations
  • Time complexity O(n log n) due to sorting and heap operations
  • Correctness proof via exchange argument or induction
  • Handling of infeasible tasks by removing the longest duration
  • Comparison with alternative approaches (e.g., dynamic programming for weighted version)
  • Space complexity O(n) for the heap

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.