# Amazon Interview Questions with Answers

6 previously-asked interview questions from Amazon's hiring process, each with the correct answer and a worked explanation. Written against the company's actual test pattern.

_Source: Astra (https://useastra.in). Updated 2026-09-05._

### 1. How do you approach solving a data structures problem in an interview?

**Answer:** Clarify the problem and constraints, work through examples, state a brute force approach and its complexity, then optimise (better data structures, two pointers, hashing, DP). Code cleanly, dry-run on examples and edge cases, and state final time and space complexity.

**Explanation:** Clarify, brute force, optimise, code, test, state complexity.

### 2. What is the difference between BFS and DFS?

**Answer:** BFS explores level by level using a queue and finds shortest paths in unweighted graphs. DFS goes as deep as possible using a stack or recursion and suits connectivity, cycle detection, and topological sorting. BFS uses more memory on wide graphs; DFS on deep ones.

**Explanation:** BFS: queue, level order, shortest path. DFS: stack, deep exploration.

### 3. What is dynamic programming?

**Answer:** Dynamic programming solves problems with overlapping subproblems and optimal substructure by storing subproblem results (memoisation or tabulation) to avoid recomputation. Examples include knapsack, longest common subsequence, and coin change.

**Explanation:** Store overlapping subproblem results to avoid recomputation.

### 4. What is a hash collision and how is it resolved?

**Answer:** A collision is when two keys hash to the same bucket. It is handled by chaining (a list or tree per bucket) or open addressing (probing for the next slot). A good hash function and low load factor keep collisions rare.

**Explanation:** Two keys share a bucket; chaining or open addressing.

### 5. Explain the tradeoff between time and space complexity with an example.

**Answer:** Often you can trade memory for speed. For example, using a hash set to check duplicates is O(n) time but O(n) space, while sorting first is O(n log n) time but O(1) extra space. The right choice depends on constraints like input size and memory limits.

**Explanation:** Trading memory for speed; choose based on constraints.

### 6. Tell me about a time you took ownership of a problem end to end.

**Answer:** Use the STAR format and map it to the Ownership Leadership Principle: describe a situation where you took responsibility beyond your immediate task, the actions you drove, and the result. Show initiative and long-term thinking.

**Explanation:** STAR mapped to Ownership; show initiative and results.

More Amazon preparation, including the full recruitment process: https://useastra.in/campus/amazon
