

by Sean Prashad
A collection of 178 questions grouped by pattern to help you prepare for coding interviews.
In 2019, as a broke college student who couldn't afford premium interview resources, I spent countless hours searching for free materials and teaching myself React to build Leetcode Patterns.
I believe everyone deserves access to high-quality interview material - regardless of their financial situation. It's why I chose to make this website free and open source.
Best of luck on your journey!
Based on the problem constraints, use these heuristics to identify possible approaches when unsure.
| Condition | Approach |
|---|---|
| Arrays & Strings | |
| If input array is sorted | Binary search, Two pointers |
If need O(1) lookup | Hash table, Hash set |
| If must solve in-place | Swap corresponding values, Store multiple values in the same pointer |
| If asked for common strings | Map, Trie |
| If asked to count bits or use XOR | Bit manipulation |
| Subarrays & Sequences | |
| If asked for max/min subarray/subset | Dynamic programming, Sliding window |
| If asked for sliding window max/min | Monotonic queue |
| If asked for next greater/smaller element | Monotonic stack |
| If need range sum/frequency queries | Prefix sum, Binary indexed tree, Segment tree |
| Trees & Graphs | |
| If given a tree | DFS, BFS |
| If given a graph | DFS, BFS, Union-Find |
| If given a matrix | BFS, DFS, Dynamic programming |
| If asked for connectivity/grouping | Union-Find, DFS |
| If asked for ordering/scheduling | Topological sort |
| Linked Lists & Stacks | |
| If given a linked list | Two pointers |
| If recursion is banned | Stack |
| Sorting & Intervals | |
If asked for top/least K items | Heap, Quickselect, Bucket sort |
| If asked to merge sorted lists/intervals | Merge sort, Heap |
| If asked for overlapping intervals | Sorting, Sweep line |
| If given a stream of data | Heap, Design |
| Optimization | |
| If asked for all permutations/subsets | Backtracking |
| If need to count/divide optimally | Greedy, Dynamic programming |
| General | |
| Else | Map/Set for O(1) time & O(n) space, Sort input for O(nlogn) time and O(1) space |
Leetcode Patterns wouldn't exist without the following resources: