← Amazon Interview Insights

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

IntermediatePrefer not to say
May 2026

Summary

Amazon SWE interview that went deep into routing and pathfinding for a delivery robot scenario. Felt like a graph problem at first but it kept growing into something closer to TSP territory, which I was not fully prepared for.

Questions Asked (4)

Q1

You have a delivery robot on a 2D grid with obstacles. Given a start position, a list of pickup locations, and their corresponding drop-off locations, find the most efficient route the robot can take to complete all deliveries. Each pickup must happen before its corresponding drop-off.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

Started with BFS for point-to-point shortest paths and that part went fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a shortest path search in a state space where each state includes the robot's position and the set of completed pickups/dropoffs. Use BFS or Dijkstra on this state graph, respecting precedence constraints. Discuss trade-offs between optimality and efficiency, and consider heuristics for large instances.

Pro tip: Start by clarifying constraints (grid size, number of deliveries) to determine if an exact algorithm is feasible or if a heuristic is needed. Mentioning real-world Amazon robotics constraints (e.g., dynamic obstacles, battery life) shows practical insight.

1. Clarify Requirements and Constraints

Ask about grid size, number of deliveries, obstacle density, and whether the robot can carry multiple items. This determines algorithm choice and scalability.

2. Define State Space and Transitions

Represent each state as (position, set of picked-up items, set of delivered items). Transitions are moves to adjacent cells, with actions to pick up or drop off when at a location.

3. Choose Search Algorithm

Use BFS for unweighted grids or Dijkstra/A* for weighted costs. For small instances, exhaustive search with pruning; for larger, consider heuristics like nearest-neighbor or genetic algorithms.

4. Handle Precedence Constraints

Enforce that a drop-off state is only reachable after the corresponding pickup. This can be done by including pickup status in the state or by ordering actions.

5. Analyze Complexity and Optimize

Discuss time/space complexity (exponential in number of deliveries). Suggest optimizations like bidirectional search, memoization, or decomposition into subproblems.

Key Points to Mention

  • State space representation including position and delivery status
  • Precedence constraints (pickup before drop-off)
  • Algorithm choices: BFS, Dijkstra, A*, or TSP-like heuristics
  • Complexity analysis and scalability concerns
  • Trade-offs between optimality and computational efficiency
  • Potential for real-world extensions (dynamic obstacles, multiple robots)

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

Q2

How would your approach change if the robot has a maximum carrying capacity, meaning it can only hold a limited number of packages at once?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Capacity constraints on top of the routing problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that the problem becomes a variant of the Vehicle Routing Problem with Capacity Constraints (CVRP). Then, discuss how to adapt your algorithm—likely from a greedy or dynamic programming approach to one that incorporates capacity as a state dimension, such as DP with state (location, remaining capacity) or a heuristic like savings algorithm. Finally, analyze trade-offs in time/space complexity and scalability, and mention potential optimizations like pruning or approximation algorithms.

Pro tip: Explicitly connect the capacity constraint to real-world Amazon scenarios, such as delivery drones or warehouse robots, and emphasize that while exact solutions may be NP-hard, practical heuristics and approximations are often preferred in production systems.

1. Clarify the problem and constraints

Restate the problem: the robot can carry at most K packages at once, and must return to the depot to reload. Ask if there are time windows, multiple robots, or other constraints.

2. Identify the algorithmic impact

Explain that without capacity, the problem might be a shortest path or TSP; with capacity, it becomes a CVRP, which is NP-hard. The state space now includes remaining capacity.

3. Propose adapted algorithms

Suggest approaches: dynamic programming with state (current node, remaining capacity, visited set) for small instances; heuristics like Clarke-Wright savings, sweep algorithm, or metaheuristics (e.g., genetic algorithms) for larger instances.

4. Analyze trade-offs

Discuss time/space complexity increases, potential need for approximation, and how to balance optimality with scalability. Mention that exact DP may be exponential, so heuristics are often used.

5. Consider practical optimizations

Mention techniques like pruning, memoization, or using OR-Tools. Also, discuss how to handle dynamic changes (e.g., new orders) with re-optimization or online algorithms.

Key Points to Mention

  • The problem transforms into a Capacitated Vehicle Routing Problem (CVRP), which is NP-hard.
  • State space expansion: DP state must include remaining capacity, increasing complexity.
  • Heuristic approaches: savings algorithm, sweep, or metaheuristics for large-scale instances.
  • Trade-offs: exact solutions vs. approximations; time/space complexity vs. optimality.
  • Real-world relevance: Amazon's delivery drones/robots often have capacity limits, so practical heuristics are key.
  • Potential optimizations: pruning, memoization, or using existing libraries like Google OR-Tools.

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

Q3

For small numbers of pickups, can you solve this optimally? What algorithm would you use and what is the complexity?

Algorithms & Data Structures
Author's notes

DP over visited subsets, classic bitmask approach.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints (e.g., number of pickups, graph size, whether pickups are on a grid or general graph). Then, propose an exact algorithm like dynamic programming with bitmask (Held-Karp) for small numbers, and analyze its time and space complexity. Finally, discuss trade-offs and potential optimizations.

Pro tip: Mention that while the exact solution is exponential, it's acceptable for small inputs, and you can optimize with memoization or pruning. Also, relate it to Amazon's leadership principles by emphasizing customer obsession (delivering optimal routes) and dive deep (understanding complexity).

1. Clarify the problem

Ask questions to understand the input size, graph structure, and whether pickups are distinct or can be grouped. Confirm that 'small numbers' means up to ~20 pickups.

2. Choose an exact algorithm

Propose using dynamic programming with bitmask (Held-Karp) to find the optimal route visiting all pickups. Explain that it computes the shortest path from a start node to all pickups and back.

3. Analyze complexity

State that the time complexity is O(2^n * n^2) and space complexity is O(2^n * n), where n is the number of pickups. Explain that this is feasible for n <= 20.

4. Discuss optimizations

Mention possible optimizations like pruning, using A* for initial pathfinding, or exploiting graph structure (e.g., Euclidean distances).

5. Compare with heuristics

Briefly note that for larger n, heuristics like nearest neighbor or genetic algorithms are used, but for small n, exact is preferred.

Key Points to Mention

  • Dynamic programming with bitmask (Held-Karp algorithm)
  • Time complexity: O(2^n * n^2), space: O(2^n * n)
  • Feasibility for n <= 20
  • Precomputation of shortest paths between pickups (e.g., Floyd-Warshall or Dijkstra)
  • Trade-off between exact and heuristic solutions
  • Potential optimizations like memoization and pruning

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

Q4

How would you handle a much larger number of delivery locations where an exact optimal solution is not computationally feasible?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Talked about heuristics: nearest-neighbor greedy, maybe some local search like 2-opt.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Acknowledge that exact optimization (e.g., solving TSP) is NP-hard and infeasible for large instances, then propose heuristic or approximation algorithms that trade optimality for scalability. Emphasize the need to balance solution quality with computational constraints, and mention specific techniques like clustering, local search, or metaheuristics.

Pro tip: Demonstrate awareness of Amazon's scale and customer obsession by discussing how to measure and minimize the impact of suboptimal routes on delivery times and costs, and mention the use of real-time data and machine learning to adapt routes dynamically.

1. Acknowledge the computational infeasibility

State that exact algorithms like dynamic programming or branch-and-bound become impractical as the number of locations grows due to exponential time complexity.

2. Propose heuristic or approximation approaches

Suggest using heuristics (e.g., nearest neighbor, savings algorithm) or approximation algorithms (e.g., Christofides for metric TSP) that provide good solutions in polynomial time.

3. Consider decomposition and clustering

Divide the problem into smaller subproblems by clustering nearby locations (e.g., using k-means or geospatial partitioning) and solve each independently, then combine.

4. Leverage metaheuristics and iterative improvement

Apply metaheuristics like simulated annealing, genetic algorithms, or ant colony optimization to refine solutions, and use local search (2-opt, 3-opt) for further optimization.

5. Evaluate trade-offs and scalability

Discuss how to measure solution quality (e.g., approximation ratio, empirical benchmarks) and ensure the approach scales with data size and real-time constraints.

Key Points to Mention

  • NP-hardness of TSP and vehicle routing problems
  • Heuristic algorithms: nearest neighbor, savings algorithm, sweep algorithm
  • Approximation algorithms: Christofides algorithm (1.5-approximation for metric TSP)
  • Metaheuristics: simulated annealing, genetic algorithms, ant colony optimization
  • Clustering and decomposition techniques (e.g., k-means, geospatial partitioning)
  • Trade-offs between optimality, computation time, and resource usage
  • Real-world constraints: time windows, vehicle capacity, dynamic routing

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