← Amazon Interview Insights

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

Senior
May 2026

Summary

Amazon SWE onsite with two meaty design-heavy coding problems back to back. Both had follow-ups on complexity and trade-offs, which is where things got interesting and occasionally uncomfortable.

Questions Asked (2)

Q1

Design a data structure for an ad-matching service that supports adding a campaign, removing a campaign, and matching an incoming request to eligible campaigns. Campaigns have targeting predicates (like location, device type, interests) and budgets. How do you optimize for fast matching given frequent updates, and what are the complexity trade-offs?

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

This one took me a while to even frame properly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and scale, then propose an inverted index over targeting attributes to quickly retrieve eligible campaigns, combined with a priority queue or budget-aware ranking. Discuss how to handle frequent updates using incremental index updates and lazy deletion, and analyze time/space trade-offs for matching, insertion, and deletion.

Pro tip: Emphasize that real ad systems often use a hybrid approach: a coarse inverted index for filtering and a fine-grained scoring model for ranking, and mention that budget constraints can be enforced via a separate real-time bidding component.

1. Clarify Requirements and Scale

Ask about the number of campaigns, request rate, update frequency, and latency requirements to determine if an in-memory or distributed solution is needed.

2. Design Core Data Structures

Propose an inverted index mapping each targeting attribute (e.g., location, device) to a set of campaign IDs, and a separate structure for budget tracking.

3. Optimize for Fast Matching

For an incoming request, intersect the posting lists of its attributes to get eligible campaigns, then rank by bid and budget using a priority queue or sorted list.

4. Handle Frequent Updates

Use incremental updates to the inverted index for additions/removals, and consider lazy deletion or tombstones to avoid costly rebalancing.

5. Analyze Complexity and Trade-offs

Discuss time complexity for matching (e.g., O(k * log n) for k attributes), insertion/deletion (O(1) amortized), and space overhead; compare with alternatives like bitmap indexes or tree-based structures.

Key Points to Mention

  • Inverted index for targeting attributes to enable fast candidate retrieval
  • Budget tracking with real-time decrement and concurrency control
  • Ranking eligible campaigns by bid and relevance using a priority queue
  • Incremental updates and lazy deletion to handle frequent campaign changes
  • Time and space complexity trade-offs between different indexing strategies
  • Scalability considerations: sharding, caching, and distributed matching

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

Q2

Given a weighted graph of roads with nonnegative edge weights, a depot, and N delivery stops, implement a function to produce a near-optimal delivery route. Walk through exact versus heuristic approaches, analyze the complexity of each, and discuss how you'd handle real-world constraints like vehicle capacity or time windows.

Algorithms & Data StructuresTechnical Trade-offsSystem Design
Author's notes

TSP question dressed up in delivery clothing.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by framing the problem as a Vehicle Routing Problem (VRP) and clarify that exact solutions are NP-hard, so heuristics are needed for large N. Then walk through exact methods (e.g., DP for small N) and heuristics (e.g., nearest neighbor, savings, 2-opt, metaheuristics), analyzing time/space complexity. Finally, discuss how to extend the model to handle capacity and time windows, emphasizing trade-offs and practical implementation.

Pro tip: Demonstrate awareness that real-world routing often uses hybrid approaches (e.g., clustering then routing) and that Amazon's scale demands distributed, incremental optimization with live traffic data.

1. Clarify problem and constraints

Restate the problem as a VRP, confirm assumptions (e.g., symmetric graph, metric), and ask about scale (N) and real-time requirements. This shows you understand the problem space before diving into algorithms.

2. Exact approaches and complexity

For small N, mention exact methods like Held-Karp DP (O(N^2 2^N)) or branch-and-bound, and note they become infeasible as N grows. Analyze time and space complexity clearly.

3. Heuristic and approximation approaches

Describe constructive heuristics (nearest neighbor, Clarke-Wright savings) and improvement heuristics (2-opt, 3-opt, Lin-Kernighan). For larger instances, mention metaheuristics (simulated annealing, genetic algorithms) and their typical complexity (e.g., O(N^2) per iteration).

4. Handle real-world constraints

Explain how to incorporate capacity (CVRP) and time windows (VRPTW) by modifying the objective and constraints, and using specialized heuristics (e.g., savings with capacity, insertion heuristics with time windows). Discuss trade-offs between optimality and feasibility.

5. Implementation and scalability

Outline a practical implementation: preprocess graph (e.g., compute shortest paths), choose algorithm based on N, and consider distributed or incremental optimization for large-scale systems. Mention evaluation metrics (total distance, runtime).

Key Points to Mention

  • NP-hardness of TSP/VRP and the need for heuristics at scale
  • Exact algorithms: Held-Karp DP, branch-and-bound, and their exponential complexity
  • Constructive heuristics: nearest neighbor, Clarke-Wright savings; improvement: 2-opt, 3-opt
  • Metaheuristics: simulated annealing, genetic algorithms, ant colony optimization
  • Capacity constraints (CVRP) and time windows (VRPTW) and how they alter the problem
  • Real-world considerations: dynamic traffic, multiple vehicles, distributed optimization

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