Company Prep
Amazon OA Coding Questions: Patterns That Repeat
The coding patterns behind Amazon OA questions — with approach breakdowns and free practice questions for each pattern.
Amazon OAs feel random until you see the patterns. These five patterns cover most of what actually appears.
Pattern 1: Hash map counting
Pair sums, anagram detection, frequency of characters, finding duplicates — these appear in nearly every OA. The signature move is a single pass with a hash map plus an O(1) lookup.
Practice variants like counting pairs with a target difference and longest substring without repeating characters — Amazon reuses these families.
Pattern 2: Sliding window and prefix sums
Subarray problems — maximum sum, target sum subarrays, window with constraint — usually reduce to a sliding window or prefix sum map. The clue is a contiguous subarray or substring constraint.
These problems punish naive double loops under big constraints, so always compute the window math before coding.
Pattern 3: Sorting plus greedy
Interval problems, scheduling, and selection problems hide behind a sort: sort by end time, then scan greedily. Merge intervals, meeting rooms, and similar variants are frequent OA material.
The complexity is usually O(n log n) from the sort — state it before writing code so you know you are done.
Pattern 4: BFS/DFS on grids and graphs
Grid traversal, connected components, and shortest path with a twist show up regularly. Practice BFS for shortest steps and DFS for counting or grouping, with visited arrays to avoid cycles.
Edge cases: blocked cells, multi-source starts, and large grids that need iterative (not recursive) DFS.
Pattern 5: Basic DP with memoization
Simple recursion-plus-cache problems — climbing stairs, house robber, unique paths — appear often at easy-medium level. Recognize the state (position, remaining, carry) and write the memo.
If a problem has an optimal substructure and asks for count, max, or min, DP or greedy is likely the route.
Continue this workflow
Put the guide into practice with the most relevant tools and supporting resources.
