Pattern track
27 patterns. Six problems each. That is the interview.
Interviews do not test 161 separate problems; they test whether you recognise which of these 27 shapes a new problem has. Each page below explains the pattern, gives you a template you can run, and six problems chosen to teach it in order of difficulty.
- Patterns
- 27
- Problems
- 161
- With a write-up here
- 110
Arrays and strings
- 01Sliding WindowKeep a contiguous window over an array or string and move its edges instead of re-scanning every subarray.6 problems · O(n) time, O(k) space for the window summary
- 02Two PointersWalk two indices toward each other over sorted data so each comparison rules out a whole group of candidate pairs.6 problems · O(n) per inward pass, plus O(n log n) if you sort first
- 06Hashing and Frequency MapsTrade memory for speed by storing what you have already seen in a hash map or set, turning repeated searches into constant-time lookups.6 problems · O(n) average time, O(n) space
- 07Prefix SumPrecompute running totals so any subarray sum is one subtraction, and pair them with a hash map to count subarrays by their sum.6 problems · O(n) time, O(n) space
- 08Difference ArrayRecord only where each range update starts and stops, then one running sum applies every update at once.6 problems · O(n + k) time, O(n) space
Searching
- 04Binary Search on Sorted DataHalve a sorted range on every comparison to find a value, a boundary, or a turning point in logarithmic time.6 problems · O(log n) time, O(1) space
- 05Binary Search on AnswerBinary search over the range of possible answers when checking one candidate is easy but computing the best answer directly is not.6 problems · O(n log R) time, where R is the size of the answer range
Stacks, queues and heaps
- 09Monotonic StackKeep a stack in increasing or decreasing order so every element finds its next greater or smaller neighbour in one pass.6 problems · O(n) time, O(n) space
- 10Monotonic QueueMaintain a deque whose values stay ordered so the maximum or minimum of a moving window is always at the front.6 problems · O(n) time, O(k) space
- 11Heap and Top KUse a priority queue to keep only the k best items seen so far, or to always process the smallest or largest item next.6 problems · O(n log k) time, O(k) space
Sorting-based
- 12IntervalsSort intervals by start, then sweep once, merging or counting overlaps by comparing each start with the last end.6 problems · O(n log n) time for the sort, O(n) space
- 13Greedy Scheduling and SortingMake the locally best choice at each step when you can show it never blocks a better overall answer.6 problems · Usually O(n), or O(n log n) with a sort
Linked lists
- 03Fast and Slow PointersMove two pointers through a linked list at different speeds to find cycles, midpoints and offsets in one pass with no extra memory.6 problems · O(n) time, O(1) space
- 14Linked List ManipulationRewire next pointers carefully, using a dummy head and saved references so no node is lost while the list changes shape.6 problems · O(n) time, O(1) extra space for most rewiring
Trees
- 15Tree DFSSolve a tree problem by asking each subtree for an answer and combining the left and right results at the parent.6 problems · O(n) time, O(h) space for the recursion stack
- 16Tree BFS and Level OrderProcess a tree one level at a time with a queue when the answer depends on depth or on nodes that sit side by side.6 problems · O(n) time, O(w) space, where w is the widest level
- 17Binary Search Tree ProblemsUse the ordering rule of a binary search tree, smaller on the left and larger on the right, to search, validate and edit it without visiting every node.6 problems · O(h) for search and edits, O(n) for full traversals
Recursion
- 18Backtracking BasicsBuild every candidate one choice at a time, recurse, then undo the choice so the same working list serves every branch.6 problems · O(n · 2^n) for subsets, O(n · n!) for permutations
- 19Backtracking with ConstraintsBacktracking where most branches are invalid, so the speed comes from rejecting a choice as early as possible.6 problems · Exponential in the worst case; pruning decides the real cost
Graphs
- 20Graph BFS and DFSExplore connected cells or nodes with a visited mark, using DFS to cover whole components and BFS when you need the fewest steps.6 problems · O(V + E) time, O(V) space; O(rows × cols) on a grid
- 21Topological SortOrder the nodes of a directed graph so every edge points forward, and detect a cycle when no such order exists.6 problems · O(V + E) time and space
- 22Union FindTrack which elements share a group with near-constant-time merges and lookups, ideal when connections arrive one at a time.6 problems · Near O(1) amortised per operation, O(n) space
- 23Shortest PathFind the cheapest route through a weighted graph with Dijkstra for non-negative weights, or bounded relaxation when stops are limited.6 problems · O(E log V) with a binary heap
- 24Minimum Spanning Tree and Graph GreedyConnect every node at the lowest total cost by always adding the cheapest edge that does not close a cycle.6 problems · O(E log E) for Kruskal, O(V²) for Prim on a dense graph
Specialised
- 25TrieStore strings character by character in a shared tree so a prefix lookup costs the prefix length, not the number of words.6 problems · O(L) per insert or lookup, where L is the word length
- 26Bit ManipulationWork directly on binary representations with XOR, AND and shifts to count, cancel or rebuild values without extra memory.6 problems · O(n) or O(number of bits) time, O(1) space
- 271D Dynamic ProgrammingBreak a problem into a sequence of overlapping subproblems where each answer depends on a few earlier ones, and fill them in order.6 problems · O(n) time for fixed transitions, O(n · k) when each state tries k choices
Track the patterns against your own progress
Signed in, every pattern page shows which of its six you have already solved, and the same 370 problems reorder for the role you are chasing. Free.
Start freePatterns, answered
What is a DSA pattern?
A pattern is a reusable shape of solution, such as a sliding window or a monotonic stack, that solves many differently worded problems. Interviews reuse a small set of them, which is why learning the pattern and then six problems that apply it transfers better than solving problems one by one.
How many problems is that in total?
161 distinct LeetCode problems across 27 patterns (162 slots; Top K Frequent Elements appears under both hashing and heaps because it teaches both). 110 of them are in the curated 370 on this site with their own write-up, examples and an in-browser editor.
In what order should I learn them?
The order on this page. Arrays and strings first, because sliding window, two pointers and hashing appear inside most later patterns. Graphs and dynamic programming come last because they assume the earlier ones.