← Amazon Interview Insights

Amazon·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Jun 2026

Summary

Amazon SWE online assessment, one algorithmic problem about allocating extra time across tasks to maximize completions. Pretty clean greedy problem once you see it, but I second-guessed myself on the sorting logic for a bit.

Questions Asked (1)

Q1

Given two arrays representing the required time and already-spent time for each task, plus a fixed budget of extra time you can distribute freely, return the maximum number of tasks you can complete.

Algorithms & Data Structures
Author's notes

The key is computing remaining time per task and then sorting by that ascending, then greedily picking the cheapest tasks until you run out of budget.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, compute the additional time needed for each task by subtracting already-spent time from required time. Then, sort these additional times in ascending order and greedily allocate the budget to the tasks with the smallest additional time until the budget is exhausted, counting the tasks completed. This greedy strategy maximizes the number of tasks because selecting tasks with minimal extra time leaves more budget for others.

Pro tip: Explicitly state the greedy choice and prove its optimality by an exchange argument: any optimal solution can be transformed to include the task with the smallest additional time without reducing the total count. This demonstrates algorithmic rigor and impresses interviewers.

1. Understand the problem

Clarify that each task requires a certain total time, some of which is already spent, and you can add extra time from a fixed budget to complete tasks. The goal is to maximize the number of completed tasks.

2. Compute additional time needed

For each task, calculate the extra time required as max(0, required_time - already_spent_time). If already_spent_time >= required_time, the task is already complete and requires no extra time.

3. Sort tasks by additional time

Sort the list of additional times in non-decreasing order. This allows you to prioritize tasks that require the least extra time.

4. Greedily allocate budget

Iterate through the sorted list, and for each task, if the additional time is less than or equal to the remaining budget, subtract it from the budget and increment the count. Stop when the budget is insufficient for the next task.

5. Return the count

The count of tasks completed is the maximum number achievable with the given budget.

Key Points to Mention

  • Greedy algorithm: always pick the task with the smallest additional time first.
  • Sorting the additional times in ascending order to facilitate the greedy choice.
  • Time complexity: O(n log n) due to sorting, which is optimal for this approach.
  • Space complexity: O(n) for storing additional times, or O(1) if modifying input in place.
  • Edge cases: tasks already completed (additional time 0), budget insufficient for any task, all tasks completable.
  • Proof of optimality: exchange argument showing that any optimal solution can be modified to include the smallest additional time task without reducing the count.

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