Amazon is famous for focusing not just on coding ability but on patterns β reusable problem-solving approaches. Mastering these patterns allows you to handle a wide range of problems with confidence. In this series, weβll break down the most commonly asked patterns at Amazon with explanations, real interview-style problems, and Java code snippets.
Part 1 β Sliding Window Pattern
- Why Amazon asks this: Efficient handling of subarrays/substrings with optimal space-time complexity.
-
Key problems:
- Longest Substring Without Repeating Characters
- Minimum Window Substring
- Maximum Sum Subarray of Size K
Core idea: Maintain a window over a sequence and adjust it using two pointers.
Java snippet: Efficient sliding window implementation.
Part 2 β Two Pointers Pattern
- Why Amazon asks this: Optimizes O(nΒ²) brute-force approaches into O(n).
-
Key problems:
- Container With Most Water
- 3Sum Closest
- Move Zeroes
Core idea: Sort or use opposite ends of an array to converge on an answer.
Part 3 β Fast & Slow Pointers (Floydβs Cycle)
- Why Amazon asks this: Linked list & cycle detection are classics.
-
Key problems:
- Detect Cycle in Linked List
- Find the Middle Node of a Linked List
- Happy Number Problem
Core idea: Two pointers moving at different speeds to detect patterns.
Part 4 β Merge Intervals Pattern
- Why Amazon asks this: Scheduling & interval merging is common in large-scale systems.
-
Key problems:
- Merge Intervals
- Insert Interval
- Minimum Meeting Rooms
Core idea: Sort by start time, merge overlapping intervals.
Part 5 β Monotonic Stack & Queue Pattern
- Why Amazon asks this: Efficient next greater/smaller element problems.
-
Key problems:
- Next Greater Element
- Daily Temperatures
- Trapping Rain Water
Core idea: Use a stack/queue to maintain monotonic order.
Part 6 β Binary Search on Answer
- Why Amazon asks this: Many optimization problems reduce to binary search on solution space.
-
Key problems:
- Koko Eating Bananas
- Capacity to Ship Packages within D Days
- Split Array Largest Sum
Core idea: Search over range of possible answers instead of raw array.
Part 7 β Backtracking & DFS Patterns
- Why Amazon asks this: Tests recursion, state-space search, and optimization.
-
Key problems:
- Word Search
- N-Queens
- Generate Parentheses
Core idea: Explore all possibilities using recursion + pruning.
Part 8 β Dynamic Programming Patterns
- Why Amazon asks this: DP is the most frequent advanced topic at Amazon.
-
Key problems:
- Longest Common Subsequence
- Coin Change
- Maximum Subarray (Kadaneβs Algorithm)
Core idea: Breaking problems into overlapping subproblems, memoization, tabulation.
Part 9 β Greedy & Heap Patterns
- Why Amazon asks this: Optimizing real-world scenarios with minimal operations.
-
Key problems:
- Top K Frequent Elements
- Meeting Rooms II (min heap)
- Reorganize String
Core idea: Locally optimal decisions leading to globally optimal solutions.
Part 10 β Graph & BFS/DFS Patterns
- Why Amazon asks this: Amazon loves graph-based thinking for logistics, routing, dependencies.
-
Key problems:
- Rotten Oranges (BFS)
- Course Schedule (Topological Sort)
- Word Ladder
Core idea: Traversal, shortest paths, cycle detection.
β Each part of the series will contain:
- Introduction to the pattern
- Why Amazon uses it (interview insights)
- Common problems
- Java code templates
- Practice exercises
Top comments (0)