← Amazon Interview Insights

Amazon·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Amazon SWE coding round with two algorithmic problems. Both were math/logic heavy and the second one had a tricky scheduling twist that I didn't fully see coming.

Questions Asked (2)

Q1

Given four integers a, b, c, d (each between 1 and 1000), you can repeatedly apply either (a, b) -> (a+b, b) or (a, b) -> (a, a+b). Determine whether it's possible to transform the pair (a, b) into (c, d).

Algorithms & Data Structures
Author's notes

My first instinct was to go forward from (a, b) and BFS toward (c, d), but the values can balloon fast and I started second-guessing the bounds.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize that the operations are reversible: from (c, d) we can subtract the smaller from the larger to move backwards. Use the Euclidean algorithm to repeatedly reduce the larger number modulo the smaller, checking if we can reach (a, b). This approach is efficient and handles large numbers.

Pro tip: Mention that the modulo optimization reduces time complexity from O(max(a,b)) to O(log(max(a,b))), which is crucial for large inputs. Also, clarify that the order of the pair matters, so (a, b) and (b, a) are distinct unless a=b.

1. Understand the operations

The operations are (a, b) -> (a+b, b) and (a, b) -> (a, a+b). They are reversible: from (x, y) with x > y, the previous state must be (x-y, y).

2. Work backwards from target

Start with (c, d) and repeatedly subtract the smaller from the larger to try to reach (a, b). Use modulo to skip multiple subtractions at once.

3. Apply Euclidean-like reduction

While both numbers are positive, if the larger is greater than the smaller, replace the larger with larger % smaller. If the smaller becomes 0, stop.

4. Check for match

At each step, check if the current pair equals (a, b) or (b, a) (since operations are symmetric in reverse). If found, return true.

5. Handle edge cases

If a or b is 0, only possible if the other equals c or d appropriately. Also, if a > c or b > d, impossible unless the other matches.

Key Points to Mention

  • Reversibility of operations: subtracting the smaller from the larger undoes an operation.
  • Euclidean algorithm analogy: the process is similar to computing gcd.
  • Modulo optimization: using larger % smaller to skip many steps.
  • Time complexity: O(log(max(c,d))) with modulo, O(max(c,d)) without.
  • Order sensitivity: (a,b) and (b,a) are different unless a=b.
  • Edge cases: when one number is 1, or when a or b is greater than c or d.

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

Q2

You have n tasks, each with a memory requirement and a type. Tasks take 1 unit of time individually, but two tasks of the same type can run in parallel if their combined memory doesn't exceed a given limit. What's the minimum total time to complete all tasks?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The example they gave (answer = 3 for 4 tasks) helped me sanity check but I still fumbled the pairing logic initially.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that each task takes 1 unit of time, but two tasks of the same type can run in parallel if their combined memory is within the limit. Then, for each type, pair tasks to maximize parallelism using a greedy two-pointer approach after sorting by memory, and sum the time slots across all types. Finally, discuss the time complexity and potential trade-offs.

Pro tip: Explicitly state that tasks of different types cannot be paired, so the problem decomposes by type. This shows you understand the constraints and avoids overcomplicating the solution.

1. Clarify the problem

Confirm that each task takes 1 unit of time, and two tasks of the same type can run in parallel only if their combined memory does not exceed the limit. Also confirm that tasks of different types cannot be paired.

2. Group tasks by type

Separate the tasks into groups based on their type. The problem then reduces to solving the minimum time for each type independently.

3. Pair tasks within each type

For each type, sort the memory requirements. Use a two-pointer technique: pair the smallest with the largest if their sum is within the limit; otherwise, the largest runs alone. Count the number of time slots needed.

4. Sum the times across types

Add the minimum time slots required for each type to get the total minimum time to complete all tasks.

5. Analyze complexity and trade-offs

Discuss the time complexity (O(n log n) due to sorting) and space complexity (O(n) for grouping). Mention that the greedy pairing is optimal for each type.

Key Points to Mention

  • The problem decomposes by task type because only same-type tasks can run in parallel.
  • For each type, the optimal strategy is to pair the smallest and largest memory tasks if their sum is within the limit, using a two-pointer approach after sorting.
  • If the sum exceeds the limit, the largest task must run alone, and we move the right pointer left.
  • The total time is the sum of the minimum time slots for each type.
  • Time complexity is O(n log n) due to sorting, and space complexity is O(n) for grouping.
  • This greedy approach is optimal because it maximizes the number of pairs, minimizing the number of time slots.

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